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