|
|
7ebc05 |
commit 3cd57be790a6455b115d07c31bdb9a72767d7ee8
|
|
|
7ebc05 |
Author: Andrew Beekhof <andrew@beekhof.net>
|
|
|
7ebc05 |
Date: Tue Apr 8 14:45:24 2014 +1000
|
|
|
7ebc05 |
|
|
|
7ebc05 |
Refactor: logging: Simplify processing of logging directives
|
|
|
7ebc05 |
|
|
|
7ebc05 |
(cherry picked from commit b3b5a57bca646377f644ff91ff724062ec8ec460)
|
|
|
7ebc05 |
|
|
|
7ebc05 |
Conflicts:
|
|
|
7ebc05 |
mcp/corosync.c
|
|
|
7ebc05 |
|
|
|
7ebc05 |
diff --git a/lib/ais/utils.c b/lib/ais/utils.c
|
|
|
7ebc05 |
index 465e381..0a3f95e 100644
|
|
|
7ebc05 |
--- a/lib/ais/utils.c
|
|
|
7ebc05 |
+++ b/lib/ais/utils.c
|
|
|
7ebc05 |
@@ -237,7 +237,7 @@ spawn_child(crm_child_t * child)
|
|
|
7ebc05 |
/* *INDENT-ON* */
|
|
|
7ebc05 |
|
|
|
7ebc05 |
if (pcmk_env.logfile) {
|
|
|
7ebc05 |
- setenv("HA_debugfile", pcmk_env.logfile, 1);
|
|
|
7ebc05 |
+ setenv("HA_logfile", pcmk_env.logfile, 1);
|
|
|
7ebc05 |
}
|
|
|
7ebc05 |
|
|
|
7ebc05 |
if (use_valgrind) {
|
|
|
7ebc05 |
diff --git a/lib/common/logging.c b/lib/common/logging.c
|
|
|
7ebc05 |
index ad6bcfd..167583e 100644
|
|
|
7ebc05 |
--- a/lib/common/logging.c
|
|
|
7ebc05 |
+++ b/lib/common/logging.c
|
|
|
7ebc05 |
@@ -234,6 +234,10 @@ crm_add_logfile(const char *filename)
|
|
|
7ebc05 |
|
|
|
7ebc05 |
if (filename == NULL) {
|
|
|
7ebc05 |
return FALSE; /* Nothing to do */
|
|
|
7ebc05 |
+ } else if(safe_str_eq(filename, "none")) {
|
|
|
7ebc05 |
+ return FALSE; /* Nothing to do */
|
|
|
7ebc05 |
+ } else if(safe_str_eq(filename, "/dev/null")) {
|
|
|
7ebc05 |
+ return FALSE; /* Nothing to do */
|
|
|
7ebc05 |
}
|
|
|
7ebc05 |
|
|
|
7ebc05 |
/* Check the parent directory */
|
|
|
7ebc05 |
@@ -317,6 +321,7 @@ crm_add_logfile(const char *filename)
|
|
|
7ebc05 |
/* Enable callsites */
|
|
|
7ebc05 |
crm_update_callsites();
|
|
|
7ebc05 |
have_logfile = TRUE;
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
return TRUE;
|
|
|
7ebc05 |
}
|
|
|
7ebc05 |
|
|
|
7ebc05 |
@@ -623,7 +628,8 @@ crm_log_init(const char *entity, int level, gboolean daemon, gboolean to_stderr,
|
|
|
7ebc05 |
int argc, char **argv, gboolean quiet)
|
|
|
7ebc05 |
{
|
|
|
7ebc05 |
int lpc = 0;
|
|
|
7ebc05 |
- const char *logfile = daemon_option("debugfile");
|
|
|
7ebc05 |
+ int32_t qb_facility = 0;
|
|
|
7ebc05 |
+ const char *logfile = daemon_option("logfile");
|
|
|
7ebc05 |
const char *facility = daemon_option("logfacility");
|
|
|
7ebc05 |
const char *f_copy = facility;
|
|
|
7ebc05 |
|
|
|
7ebc05 |
@@ -643,14 +649,7 @@ crm_log_init(const char *entity, int level, gboolean daemon, gboolean to_stderr,
|
|
|
7ebc05 |
/* and for good measure... - this enum is a bit field (!) */
|
|
|
7ebc05 |
g_log_set_always_fatal((GLogLevelFlags) 0); /*value out of range */
|
|
|
7ebc05 |
|
|
|
7ebc05 |
- if (facility == NULL) {
|
|
|
7ebc05 |
- facility = "daemon";
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
- } else if (safe_str_eq(facility, "none")) {
|
|
|
7ebc05 |
- facility = "daemon";
|
|
|
7ebc05 |
- quiet = TRUE;
|
|
|
7ebc05 |
- }
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
+ /* Who do we log as */
|
|
|
7ebc05 |
if (entity) {
|
|
|
7ebc05 |
free(crm_system_name);
|
|
|
7ebc05 |
crm_system_name = strdup(entity);
|
|
|
7ebc05 |
@@ -673,29 +672,54 @@ crm_log_init(const char *entity, int level, gboolean daemon, gboolean to_stderr,
|
|
|
7ebc05 |
|
|
|
7ebc05 |
setenv("PCMK_service", crm_system_name, 1);
|
|
|
7ebc05 |
|
|
|
7ebc05 |
- if (daemon_option_enabled(crm_system_name, "debug")) {
|
|
|
7ebc05 |
- /* Override the default setting */
|
|
|
7ebc05 |
- level = LOG_DEBUG;
|
|
|
7ebc05 |
+ /* Should we log to syslog */
|
|
|
7ebc05 |
+ if (facility == NULL) {
|
|
|
7ebc05 |
+ if(crm_is_daemon) {
|
|
|
7ebc05 |
+ facility = "daemon";
|
|
|
7ebc05 |
+ } else {
|
|
|
7ebc05 |
+ facility = "none";
|
|
|
7ebc05 |
+ }
|
|
|
7ebc05 |
+ set_daemon_option("logfacility", facility);
|
|
|
7ebc05 |
}
|
|
|
7ebc05 |
|
|
|
7ebc05 |
- if (daemon_option_enabled(crm_system_name, "stderr")) {
|
|
|
7ebc05 |
+ if (safe_str_eq(facility, "none")) {
|
|
|
7ebc05 |
+ quiet = TRUE;
|
|
|
7ebc05 |
+ qb_facility = qb_log_facility2int("daemon");
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ } else {
|
|
|
7ebc05 |
+ qb_facility = qb_log_facility2int(facility);
|
|
|
7ebc05 |
+ }
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ if (daemon_option_enabled(crm_system_name, "debug")) {
|
|
|
7ebc05 |
/* Override the default setting */
|
|
|
7ebc05 |
- to_stderr = TRUE;
|
|
|
7ebc05 |
+ level = LOG_DEBUG;
|
|
|
7ebc05 |
}
|
|
|
7ebc05 |
|
|
|
7ebc05 |
+ /* What lower threshold do we have for sending to syslog */
|
|
|
7ebc05 |
crm_log_priority = crm_priority2int(daemon_option("logpriority"));
|
|
|
7ebc05 |
|
|
|
7ebc05 |
crm_log_level = level;
|
|
|
7ebc05 |
- qb_log_init(crm_system_name, qb_log_facility2int(facility), level);
|
|
|
7ebc05 |
- qb_log_tags_stringify_fn_set(crm_quark_to_string);
|
|
|
7ebc05 |
+ qb_log_init(crm_system_name, qb_facility, crm_log_level);
|
|
|
7ebc05 |
|
|
|
7ebc05 |
- /* Set default format strings */
|
|
|
7ebc05 |
+ if (quiet) {
|
|
|
7ebc05 |
+ /* Nuke any syslog activity */
|
|
|
7ebc05 |
+ qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
|
|
|
7ebc05 |
+ }
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ /* Set format strings */
|
|
|
7ebc05 |
+ qb_log_tags_stringify_fn_set(crm_quark_to_string);
|
|
|
7ebc05 |
for (lpc = QB_LOG_SYSLOG; lpc < QB_LOG_TARGET_MAX; lpc++) {
|
|
|
7ebc05 |
set_format_string(lpc, crm_system_name);
|
|
|
7ebc05 |
}
|
|
|
7ebc05 |
|
|
|
7ebc05 |
+ /* Should we log to stderr */
|
|
|
7ebc05 |
+ if (daemon_option_enabled(crm_system_name, "stderr")) {
|
|
|
7ebc05 |
+ /* Override the default setting */
|
|
|
7ebc05 |
+ to_stderr = TRUE;
|
|
|
7ebc05 |
+ }
|
|
|
7ebc05 |
crm_enable_stderr(to_stderr);
|
|
|
7ebc05 |
|
|
|
7ebc05 |
+ /* Should we log to a file */
|
|
|
7ebc05 |
if (safe_str_eq("none", logfile)) {
|
|
|
7ebc05 |
/* No soup^Hlogs for you! */
|
|
|
7ebc05 |
} else if(crm_is_daemon) {
|
|
|
7ebc05 |
@@ -709,20 +733,11 @@ crm_log_init(const char *entity, int level, gboolean daemon, gboolean to_stderr,
|
|
|
7ebc05 |
crm_enable_blackbox(0);
|
|
|
7ebc05 |
}
|
|
|
7ebc05 |
|
|
|
7ebc05 |
+ /* Summary */
|
|
|
7ebc05 |
crm_trace("Quiet: %d, facility %s", quiet, f_copy);
|
|
|
7ebc05 |
- daemon_option("debugfile");
|
|
|
7ebc05 |
+ daemon_option("logfile");
|
|
|
7ebc05 |
daemon_option("logfacility");
|
|
|
7ebc05 |
|
|
|
7ebc05 |
- if (quiet) {
|
|
|
7ebc05 |
- /* Nuke any syslog activity */
|
|
|
7ebc05 |
- facility = NULL;
|
|
|
7ebc05 |
- qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
|
|
|
7ebc05 |
- }
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
- if (crm_is_daemon) {
|
|
|
7ebc05 |
- set_daemon_option("logfacility", facility);
|
|
|
7ebc05 |
- }
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
crm_update_callsites();
|
|
|
7ebc05 |
|
|
|
7ebc05 |
/* Ok, now we can start logging... */
|
|
|
7ebc05 |
diff --git a/mcp/corosync.c b/mcp/corosync.c
|
|
|
7ebc05 |
index a97c8d8..24f5c22 100644
|
|
|
7ebc05 |
--- a/mcp/corosync.c
|
|
|
7ebc05 |
+++ b/mcp/corosync.c
|
|
|
7ebc05 |
@@ -266,16 +266,9 @@ mcp_read_config(void)
|
|
|
7ebc05 |
{
|
|
|
7ebc05 |
int rc = CS_OK;
|
|
|
7ebc05 |
int retries = 0;
|
|
|
7ebc05 |
- gboolean have_log = FALSE;
|
|
|
7ebc05 |
|
|
|
7ebc05 |
const char *const_value = NULL;
|
|
|
7ebc05 |
|
|
|
7ebc05 |
- char *logging_debug = NULL;
|
|
|
7ebc05 |
- char *logging_logfile = NULL;
|
|
|
7ebc05 |
- char *logging_to_logfile = NULL;
|
|
|
7ebc05 |
- char *logging_to_syslog = NULL;
|
|
|
7ebc05 |
- char *logging_syslog_facility = NULL;
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
#if HAVE_CONFDB
|
|
|
7ebc05 |
char *value = NULL;
|
|
|
7ebc05 |
confdb_handle_t config = 0;
|
|
|
7ebc05 |
@@ -379,35 +372,83 @@ mcp_read_config(void)
|
|
|
7ebc05 |
#endif
|
|
|
7ebc05 |
|
|
|
7ebc05 |
/* =::=::= Logging =::=::= */
|
|
|
7ebc05 |
- get_config_opt(config, local_handle, KEY_PREFIX "debug", &logging_debug, "off");
|
|
|
7ebc05 |
+ if (daemon_option("debug")) {
|
|
|
7ebc05 |
+ /* Syslog logging is already setup by crm_log_init() */
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ } else {
|
|
|
7ebc05 |
+ /* Check corosync */
|
|
|
7ebc05 |
+ char *debug_enabled = NULL;
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ get_config_opt(config, local_handle, KEY_PREFIX "debug", &debug_enabled, "off");
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ if (crm_is_true(debug_enabled)) {
|
|
|
7ebc05 |
+ set_daemon_option("debug", "1");
|
|
|
7ebc05 |
+ if (get_crm_log_level() < LOG_DEBUG) {
|
|
|
7ebc05 |
+ set_crm_log_level(LOG_DEBUG);
|
|
|
7ebc05 |
+ }
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ } else {
|
|
|
7ebc05 |
+ set_daemon_option("debug", "0");
|
|
|
7ebc05 |
+ }
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ free(debug_enabled);
|
|
|
7ebc05 |
+ }
|
|
|
7ebc05 |
|
|
|
7ebc05 |
const_value = daemon_option("debugfile");
|
|
|
7ebc05 |
- if (const_value) {
|
|
|
7ebc05 |
- logging_to_logfile = strdup("on");
|
|
|
7ebc05 |
- logging_logfile = strdup(const_value);
|
|
|
7ebc05 |
- crm_trace("Using debugfile setting from the environment: %s", logging_logfile);
|
|
|
7ebc05 |
+ if (daemon_option("logfile")) {
|
|
|
7ebc05 |
+ /* File logging is already setup by crm_log_init() */
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ } else if(const_value) {
|
|
|
7ebc05 |
+ /* From when we cared what options heartbeat used */
|
|
|
7ebc05 |
+ set_daemon_option("logfile", const_value);
|
|
|
7ebc05 |
+ crm_add_logfile(const_value);
|
|
|
7ebc05 |
|
|
|
7ebc05 |
} else {
|
|
|
7ebc05 |
- get_config_opt(config, local_handle, KEY_PREFIX "to_logfile", &logging_to_logfile, "off");
|
|
|
7ebc05 |
- get_config_opt(config, local_handle, KEY_PREFIX "logfile", &logging_logfile,
|
|
|
7ebc05 |
- "/var/log/pacemaker");
|
|
|
7ebc05 |
- }
|
|
|
7ebc05 |
+ /* Check corosync */
|
|
|
7ebc05 |
+ char *logfile = NULL;
|
|
|
7ebc05 |
+ char *logfile_enabled = NULL;
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ get_config_opt(config, local_handle, KEY_PREFIX "to_logfile", &logfile_enabled, "on");
|
|
|
7ebc05 |
+ get_config_opt(config, local_handle, KEY_PREFIX "logfile", &logfile, "/var/log/pacemaker.log");
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ if (crm_is_true(logfile_enabled) == FALSE) {
|
|
|
7ebc05 |
+ crm_trace("File logging disabled in corosync");
|
|
|
7ebc05 |
|
|
|
7ebc05 |
- const_value = daemon_option("logfacility");
|
|
|
7ebc05 |
- if (const_value) {
|
|
|
7ebc05 |
- logging_syslog_facility = strdup(const_value);
|
|
|
7ebc05 |
- crm_trace("Using logfacility setting from the environment: %s", logging_syslog_facility);
|
|
|
7ebc05 |
+ } else if (crm_add_logfile(logfile)) {
|
|
|
7ebc05 |
+ set_daemon_option("logfile", logfile);
|
|
|
7ebc05 |
|
|
|
7ebc05 |
- if (safe_str_eq(logging_syslog_facility, "none")) {
|
|
|
7ebc05 |
- logging_to_syslog = strdup("off");
|
|
|
7ebc05 |
} else {
|
|
|
7ebc05 |
- logging_to_syslog = strdup("on");
|
|
|
7ebc05 |
+ crm_err("Couldn't create logfile: %s", logfile);
|
|
|
7ebc05 |
+ set_daemon_option("logfile", "none");
|
|
|
7ebc05 |
}
|
|
|
7ebc05 |
|
|
|
7ebc05 |
+ free(logfile);
|
|
|
7ebc05 |
+ free(logfile_enabled);
|
|
|
7ebc05 |
+ }
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ if (daemon_option("logfacility")) {
|
|
|
7ebc05 |
+ /* Syslog logging is already setup by crm_log_init() */
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
} else {
|
|
|
7ebc05 |
- get_config_opt(config, local_handle, KEY_PREFIX "to_syslog", &logging_to_syslog, "on");
|
|
|
7ebc05 |
- get_config_opt(config, local_handle, KEY_PREFIX "syslog_facility", &logging_syslog_facility,
|
|
|
7ebc05 |
- "daemon");
|
|
|
7ebc05 |
+ /* Check corosync */
|
|
|
7ebc05 |
+ char *syslog_enabled = NULL;
|
|
|
7ebc05 |
+ char *syslog_facility = NULL;
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ get_config_opt(config, local_handle, KEY_PREFIX "to_syslog", &syslog_enabled, "on");
|
|
|
7ebc05 |
+ get_config_opt(config, local_handle, KEY_PREFIX "syslog_facility", &syslog_facility, "daemon");
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ if (crm_is_true(syslog_enabled) == FALSE) {
|
|
|
7ebc05 |
+ qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
|
|
|
7ebc05 |
+ set_daemon_option("logfacility", "none");
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ } else {
|
|
|
7ebc05 |
+ qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_FACILITY, qb_log_facility2int(syslog_facility));
|
|
|
7ebc05 |
+ qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_TRUE);
|
|
|
7ebc05 |
+ set_daemon_option("logfacility", syslog_facility);
|
|
|
7ebc05 |
+ }
|
|
|
7ebc05 |
+
|
|
|
7ebc05 |
+ free(syslog_enabled);
|
|
|
7ebc05 |
+ free(syslog_facility);
|
|
|
7ebc05 |
}
|
|
|
7ebc05 |
|
|
|
7ebc05 |
#if HAVE_CONFDB
|
|
|
7ebc05 |
@@ -429,52 +470,5 @@ mcp_read_config(void)
|
|
|
7ebc05 |
cmap_finalize(local_handle);
|
|
|
7ebc05 |
#endif
|
|
|
7ebc05 |
|
|
|
7ebc05 |
- if (daemon_option("debug")) {
|
|
|
7ebc05 |
- crm_trace("Using debug setting from the environment: %s", daemon_option("debug"));
|
|
|
7ebc05 |
- if (get_crm_log_level() < LOG_DEBUG && daemon_option_enabled("pacemakerd", "debug")) {
|
|
|
7ebc05 |
- set_crm_log_level(LOG_DEBUG);
|
|
|
7ebc05 |
- }
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
- } else if (crm_is_true(logging_debug)) {
|
|
|
7ebc05 |
- set_daemon_option("debug", "1");
|
|
|
7ebc05 |
- if (get_crm_log_level() < LOG_DEBUG) {
|
|
|
7ebc05 |
- set_crm_log_level(LOG_DEBUG);
|
|
|
7ebc05 |
- }
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
- } else {
|
|
|
7ebc05 |
- set_daemon_option("debug", "0");
|
|
|
7ebc05 |
- }
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
- if (crm_is_true(logging_to_logfile)) {
|
|
|
7ebc05 |
- if (crm_add_logfile(logging_logfile)) {
|
|
|
7ebc05 |
- /* What a cluster fsck, eventually we need to mandate /one/ */
|
|
|
7ebc05 |
- set_daemon_option("debugfile", logging_logfile);
|
|
|
7ebc05 |
- set_daemon_option("DEBUGLOG", logging_logfile);
|
|
|
7ebc05 |
- have_log = TRUE;
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
- } else {
|
|
|
7ebc05 |
- crm_err("Couldn't create logfile: %s", logging_logfile);
|
|
|
7ebc05 |
- }
|
|
|
7ebc05 |
- }
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
- if (have_log && crm_is_true(logging_to_syslog) == FALSE) {
|
|
|
7ebc05 |
- qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
|
|
|
7ebc05 |
- free(logging_syslog_facility);
|
|
|
7ebc05 |
- logging_syslog_facility = strdup("none");
|
|
|
7ebc05 |
- crm_info("User configured file based logging and explicitly disabled syslog.");
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
- } else if (crm_is_true(logging_to_syslog) == FALSE) {
|
|
|
7ebc05 |
- crm_err("Please enable some sort of logging, either 'to_logfile: on' or 'to_syslog: on'.");
|
|
|
7ebc05 |
- crm_err("If you use file logging, be sure to also define a value for 'logfile'");
|
|
|
7ebc05 |
- }
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
- set_daemon_option("logfacility", logging_syslog_facility);
|
|
|
7ebc05 |
- setenv("HA_LOGFACILITY", logging_syslog_facility, 1);
|
|
|
7ebc05 |
-
|
|
|
7ebc05 |
- free(logging_debug);
|
|
|
7ebc05 |
- free(logging_logfile);
|
|
|
7ebc05 |
- free(logging_to_logfile);
|
|
|
7ebc05 |
- free(logging_to_syslog);
|
|
|
7ebc05 |
- free(logging_syslog_facility);
|
|
|
7ebc05 |
return TRUE;
|
|
|
7ebc05 |
}
|
|
|
7ebc05 |
diff --git a/mcp/pacemaker.sysconfig b/mcp/pacemaker.sysconfig
|
|
|
7ebc05 |
index 7f12111..50b4814 100644
|
|
|
7ebc05 |
--- a/mcp/pacemaker.sysconfig
|
|
|
7ebc05 |
+++ b/mcp/pacemaker.sysconfig
|
|
|
7ebc05 |
@@ -14,7 +14,7 @@
|
|
|
7ebc05 |
# Send INFO (and higher) messages to the named log file
|
|
|
7ebc05 |
# Additional messages may also appear here depending on any configured debug and trace settings
|
|
|
7ebc05 |
# By default Pacemaker will inherit the logfile specified in corosync.conf
|
|
|
7ebc05 |
-# PCMK_debugfile=/var/log/pacemaker.log
|
|
|
7ebc05 |
+# PCMK_logfile=/var/log/pacemaker.log
|
|
|
7ebc05 |
|
|
|
7ebc05 |
# Specify an alternate syslog target for NOTICE (and higher) messages
|
|
|
7ebc05 |
# Use 'none' to disable - not recommended
|