41 #ifdef LOGCONFIG_USE_ICMAP
43 #define MAP_KEYNAME_MAXLEN ICMAP_KEYNAME_MAXLEN
44 #define map_get_string(key_name, value) icmap_get_string(key_name, value)
48 static const char *main_logfile;
49 #define MAP_KEYNAME_MAXLEN CMAP_KEYNAME_MAXLEN
50 #define map_get_string(key_name, value) cmap_get_string(cmap_handle, key_name, value)
56 static char error_string_response[512];
79 static int insert_into_buffer(
85 const char *current_format = NULL;
90 if (strstr(current_format, entry) != NULL) {
97 if (snprintf(target_buffer, bufferlen - 1,
"%s%s",
99 current_format) >= bufferlen - 1) {
103 const char *afterpos;
109 afterpos = strstr(current_format, after);
110 afterlen = strlen(after);
111 if ((!afterpos) || (!afterlen)) {
115 templen = afterpos - current_format + afterlen;
116 if (snprintf(target_buffer, templen + 1,
"%s", current_format)
120 if (snprintf(target_buffer + templen, bufferlen - ( templen + 1 ),
121 "%s%s", entry, current_format + templen)
122 >= bufferlen - ( templen + 1 )) {
133 static int corosync_main_config_format_set (
134 const char **error_string)
136 const char *error_reason;
137 char new_format_buffer[PATH_MAX];
142 if (strcmp (value,
"on") == 0) {
143 if (!insert_into_buffer(new_format_buffer,
144 sizeof(new_format_buffer),
148 if (!insert_into_buffer(new_format_buffer,
149 sizeof(new_format_buffer),
154 if (strcmp (value,
"off") == 0) {
157 error_reason =
"unknown value for fileline";
166 error_reason =
"not enough memory to set logging format buffer";
171 if (strcmp (value,
"on") == 0) {
172 if (!insert_into_buffer(new_format_buffer,
173 sizeof(new_format_buffer),
177 if (!insert_into_buffer(new_format_buffer,
178 sizeof(new_format_buffer),
183 if (strcmp (value,
"off") == 0) {
186 error_reason =
"unknown value for function_name";
195 error_reason =
"not enough memory to set logging format buffer";
200 if (strcmp (value,
"on") == 0) {
201 if(!insert_into_buffer(new_format_buffer,
202 sizeof(new_format_buffer),
207 if (strcmp (value,
"off") == 0) {
210 error_reason =
"unknown value for timestamp";
219 error_reason =
"not enough memory to set logging format buffer";
226 *error_string = error_reason;
235 static int corosync_main_config_blackbox_set (
236 const char **error_string)
238 const char *error_reason;
242 if (strcmp (value,
"on") == 0) {
244 }
else if (strcmp (value,
"off") == 0) {
247 error_reason =
"unknown value for blackbox";
260 *error_string = error_reason;
265 static int corosync_main_config_log_destination_set (
269 const char **error_string,
270 unsigned int mode_mask,
273 const char *replacement)
275 static char formatted_error_reason[128];
284 "Warning: the %s config parameter has been obsoleted."
285 " See corosync.conf man page %s directive.",
291 if (strcmp (value,
"yes") == 0 || strcmp (value,
"on") == 0) {
294 sprintf (formatted_error_reason,
"unable to set mode %s", key);
298 if (strcmp (value,
"no") == 0 || strcmp (value,
"off") == 0) {
301 sprintf (formatted_error_reason,
"unable to unset mode %s", key);
305 sprintf (formatted_error_reason,
"unknown value for %s", key);
310 else if (!subsys && !deprecated) {
320 sprintf (formatted_error_reason,
"unable to change mode %s", key);
329 *error_string = formatted_error_reason;
334 static int corosync_main_config_set (
337 const char **error_string)
339 const char *error_reason = error_string_response;
353 if (subsys != NULL) {
355 error_reason =
"unable to create new logging subsystem";
362 error_reason =
"unable to get mode";
366 if (corosync_main_config_log_destination_set (path,
"to_stderr", subsys, &error_reason,
370 if (corosync_main_config_log_destination_set (path,
"to_syslog", subsys, &error_reason,
378 syslog_facility = qb_log_facility2int(value);
379 if (syslog_facility < 0) {
380 error_reason =
"unknown syslog facility specified";
384 syslog_facility) < 0) {
385 error_reason =
"unable to set syslog facility";
394 qb_log_facility2int(
"daemon")) < 0) {
395 error_reason =
"unable to set syslog facility";
405 "Warning: the syslog_level config parameter has been obsoleted."
406 " See corosync.conf man page syslog_priority directive.");
411 if (syslog_priority < 0) {
412 error_reason =
"unknown syslog level specified";
416 syslog_priority) < 0) {
417 error_reason =
"unable to set syslog level";
428 if (syslog_priority < 0) {
429 error_reason =
"unknown syslog priority specified";
433 syslog_priority) < 0) {
434 error_reason =
"unable to set syslog priority";
438 else if(strcmp(key_name,
"logging.syslog_priority") == 0){
441 error_reason =
"unable to set syslog level";
446 #ifdef LOGCONFIG_USE_ICMAP
462 if (corosync_main_config_log_destination_set (path,
"to_file", subsys, &error_reason,
466 if (corosync_main_config_log_destination_set (path,
"to_logfile", subsys, &error_reason,
472 int logfile_priority;
476 if (logfile_priority < 0) {
477 error_reason =
"unknown logfile priority specified";
481 logfile_priority) < 0) {
482 error_reason =
"unable to set logfile priority";
486 else if(strcmp(key_name,
"logging.logfile_priority") == 0){
489 error_reason =
"unable to set syslog level";
496 if (strcmp (value,
"trace") == 0) {
498 error_reason =
"unable to set debug trace";
503 if (strcmp (value,
"on") == 0) {
505 error_reason =
"unable to set debug on";
510 if (strcmp (value,
"off") == 0) {
512 error_reason =
"unable to set debug off";
517 error_reason =
"unknown value for debug";
525 error_reason =
"unable to set debug off";
534 *error_string = error_reason;
539 static int corosync_main_config_read_logging (
540 const char **error_string)
542 const char *error_reason;
543 #ifdef LOGCONFIG_USE_ICMAP
545 const char *key_name;
555 if (corosync_main_config_format_set(&error_reason) < 0) {
559 if (corosync_main_config_blackbox_set(&error_reason) < 0) {
563 if (corosync_main_config_set (
"logging", NULL, &error_reason) < 0) {
571 #ifdef LOGCONFIG_USE_ICMAP
578 res = sscanf(key_name,
"logging.logger_subsys.%[^.].%s", key_subsys, key_item);
584 if (strcmp(key_item,
"subsys") != 0) {
590 if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) {
594 #ifdef LOGCONFIG_USE_ICMAP
604 *error_string = error_reason;
609 #ifdef LOGCONFIG_USE_ICMAP
610 static void main_logging_notify(
612 const char *key_name,
617 static void main_logging_notify(
621 const char *key_name,
627 const char *error_string;
628 static int reload_in_progress = 0;
633 if (strcmp(key_name,
"config.reload_in_progress") == 0) {
634 if (*(uint8_t *)new_val.
data == 1) {
635 reload_in_progress = 1;
637 reload_in_progress = 0;
640 if (reload_in_progress) {
649 fprintf (stderr,
"Unable to setup logging format.\n");
651 corosync_main_config_read_logging(&error_string);
654 #ifdef LOGCONFIG_USE_ICMAP
655 static void add_logsys_config_notification(
void)
672 static void add_logsys_config_notification(
void)
691 #ifndef LOGCONFIG_USE_ICMAP
693 const char *default_logfile,
695 const char **error_string)
697 const char *error_reason = error_string_response;
699 #ifndef LOGCONFIG_USE_ICMAP
701 error_reason =
"No cmap handle";
704 if (!default_logfile) {
705 error_reason =
"No default logfile";
709 main_logfile = default_logfile;
712 if (corosync_main_config_read_logging(error_string) < 0) {
713 error_reason = *error_string;
717 add_logsys_config_notification();
722 snprintf (error_string_response,
sizeof(error_string_response),
723 "parse error in config: %s.\n",
726 *error_string = error_string_response;
#define LOGSYS_DEBUG_TRACE
#define CMAP_TRACK_DELETE
cs_error_t cmap_track_add(cmap_handle_t handle, const char *key_name, int32_t track_type, cmap_notify_fn_t notify_fn, void *user_data, cmap_track_handle_t *cmap_track_handle)
Add tracking function for given key_name.
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Return next item in iterator iter.
#define MAP_KEYNAME_MAXLEN
#define CMAP_TRACK_MODIFY
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
cs_error_t cmap_iter_next(cmap_handle_t handle, cmap_iter_handle_t iter_handle, char key_name[], size_t *value_len, cmap_value_types_t *type)
Return next item in iterator iter.
cmap_handle_t cmap_handle
#define map_get_string(key_name, value)
#define CMAP_KEYNAME_MAXLEN
int logsys_config_file_set(const char *subsys, const char **error_string, const char *file)
to close a logfile, just invoke this function with a NULL file or if you want to change logfile...
cs_error_t cmap_iter_init(cmap_handle_t handle, const char *prefix, cmap_iter_handle_t *cmap_iter_handle)
Initialize iterator with given prefix.
int _logsys_subsys_create(const char *subsys, const char *filename)
_logsys_subsys_create
#define log_printf(level, format, args...)
Structure passed as new_value and old_value in change callback.
#define LOGSYS_MODE_OUTPUT_FILE
cs_error_t cmap_iter_finalize(cmap_handle_t handle, cmap_iter_handle_t iter_handle)
Finalize iterator.
#define ICMAP_TRACK_DELETE
#define LOGSYS_LEVEL_WARNING
#define ICMAP_TRACK_MODIFY
int logsys_config_debug_set(const char *subsys, unsigned int value)
enabling debug, disable message priority filtering.
int logsys_config_syslog_facility_set(const char *subsys, unsigned int facility)
per system/subsystem settings.
int logsys_config_mode_set(const char *subsys, unsigned int mode)
logsys_config_mode_set
char * logsys_format_get(void)
logsys_format_get
#define LOGSYS_MODE_OUTPUT_SYSLOG
int corosync_log_config_read(cmap_handle_t cmap_h, const char *default_logfile, const char **error_string)
#define LOGSYS_LEVEL_DEBUG
uint64_t cmap_track_handle_t
int logsys_config_syslog_priority_set(const char *subsys, unsigned int priority)
logsys_config_syslog_priority_set
void logsys_blackbox_set(int enable)
#define CMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem.nodeid", "totem.version", ...
void logsys_config_apply(void)
logsys_config_apply
int logsys_priority_id_get(const char *name)
logsys_priority_id_get
uint64_t cmap_iter_handle_t
unsigned int logsys_config_mode_get(const char *subsys)
logsys_config_mode_get
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
int logsys_config_logfile_priority_set(const char *subsys, unsigned int priority)
logsys_config_logfile_priority_set
#define LOGSYS_MODE_OUTPUT_STDERR
qb_map_iter_t * icmap_iter_t
Itterator type.
Structure passed as new_value and old_value in change callback.
cs_error_t icmap_track_add(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
Add tracking function for given key_name.
int logsys_format_set(const char *format)
configuration bits that can only be done for the whole system
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem.nodeid", "totem.version", ...