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)
48static 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)
57static char error_string_response[512];
80static int insert_into_buffer(
86 const char *current_format = NULL;
91 if (strstr(current_format, entry) != NULL) {
98 if (snprintf(target_buffer, bufferlen - 1,
"%s%s",
100 current_format) >= bufferlen - 1) {
104 const char *afterpos;
110 afterpos = strstr(current_format, after);
111 afterlen = strlen(after);
112 if ((!afterpos) || (!afterlen)) {
116 templen = afterpos - current_format + afterlen;
117 if (snprintf(target_buffer, templen + 1,
"%s", current_format)
121 if (snprintf(target_buffer + templen, bufferlen - ( templen + 1 ),
122 "%s%s", entry, current_format + templen)
123 >= bufferlen - ( templen + 1 )) {
134static int corosync_main_config_format_set (
135 const char **error_string)
137 const char *error_reason;
138 char new_format_buffer[PATH_MAX];
141 char timestamp_str_to_add[8];
144 if (strcmp (
value,
"on") == 0) {
145 if (!insert_into_buffer(new_format_buffer,
146 sizeof(new_format_buffer),
150 if (!insert_into_buffer(new_format_buffer,
151 sizeof(new_format_buffer),
156 if (strcmp (
value,
"off") == 0) {
159 error_reason =
"unknown value for fileline";
168 error_reason =
"not enough memory to set logging format buffer";
173 if (strcmp (
value,
"on") == 0) {
174 if (!insert_into_buffer(new_format_buffer,
175 sizeof(new_format_buffer),
179 if (!insert_into_buffer(new_format_buffer,
180 sizeof(new_format_buffer),
185 if (strcmp (
value,
"off") == 0) {
188 error_reason =
"unknown value for function_name";
197 error_reason =
"not enough memory to set logging format buffer";
201 memset(timestamp_str_to_add, 0,
sizeof(timestamp_str_to_add));
204 if (strcmp (
value,
"on") == 0) {
205 strcpy(timestamp_str_to_add,
"%t");
206#ifdef QB_FEATURE_LOG_HIRES_TIMESTAMPS
207 }
else if (strcmp (
value,
"hires") == 0) {
208 strcpy(timestamp_str_to_add,
"%T");
210 }
else if (strcmp (
value,
"off") == 0) {
213 error_reason =
"unknown value for timestamp";
223#ifdef QB_FEATURE_LOG_HIRES_TIMESTAMPS
224 strcpy(timestamp_str_to_add,
"%T");
226 strcpy(timestamp_str_to_add,
"%t");
230 if(strcmp(timestamp_str_to_add,
"") != 0) {
231 strcat(timestamp_str_to_add,
" ");
232 if (insert_into_buffer(new_format_buffer,
sizeof(new_format_buffer),
233 timestamp_str_to_add, NULL) == 0) {
239 error_reason =
"not enough memory to set logging format buffer";
246 *error_string = error_reason;
255static int corosync_main_config_blackbox_set (
256 const char **error_string)
258 const char *error_reason;
262 if (strcmp (
value,
"on") == 0) {
264 }
else if (strcmp (
value,
"off") == 0) {
267 error_reason =
"unknown value for blackbox";
280 *error_string = error_reason;
285static int corosync_main_config_log_destination_set (
289 const char **error_string,
290 unsigned int mode_mask,
293 const char *replacement)
295 static char formatted_error_reason[128];
304 "Warning: the %s config parameter has been obsoleted."
305 " See corosync.conf man page %s directive.",
311 if (strcmp (
value,
"yes") == 0 || strcmp (
value,
"on") == 0) {
314 sprintf (formatted_error_reason,
"unable to set mode %s", key);
318 if (strcmp (
value,
"no") == 0 || strcmp (
value,
"off") == 0) {
321 sprintf (formatted_error_reason,
"unable to unset mode %s", key);
325 sprintf (formatted_error_reason,
"unknown value for %s", key);
330 else if (!subsys && !deprecated) {
340 sprintf (formatted_error_reason,
"unable to change mode %s", key);
349 *error_string = formatted_error_reason;
354static int corosync_main_config_set (
357 const char **error_string)
359 const char *error_reason = error_string_response;
373 if (subsys != NULL) {
375 error_reason =
"unable to create new logging subsystem";
382 error_reason =
"unable to get mode";
386 if (corosync_main_config_log_destination_set (path,
"to_stderr", subsys, &error_reason,
390 if (corosync_main_config_log_destination_set (path,
"to_syslog", subsys, &error_reason,
398 syslog_facility = qb_log_facility2int(
value);
399 if (syslog_facility < 0) {
400 error_reason =
"unknown syslog facility specified";
404 syslog_facility) < 0) {
405 error_reason =
"unable to set syslog facility";
414 qb_log_facility2int(
"daemon")) < 0) {
415 error_reason =
"unable to set syslog facility";
425 "Warning: the syslog_level config parameter has been obsoleted."
426 " See corosync.conf man page syslog_priority directive.");
431 if (syslog_priority < 0) {
432 error_reason =
"unknown syslog level specified";
436 syslog_priority) < 0) {
437 error_reason =
"unable to set syslog level";
448 if (syslog_priority < 0) {
449 error_reason =
"unknown syslog priority specified";
453 syslog_priority) < 0) {
454 error_reason =
"unable to set syslog priority";
458 else if(strcmp(key_name,
"logging.syslog_priority") == 0){
461 error_reason =
"unable to set syslog level";
466#ifdef LOGCONFIG_USE_ICMAP
482 if (corosync_main_config_log_destination_set (path,
"to_file", subsys, &error_reason,
486 if (corosync_main_config_log_destination_set (path,
"to_logfile", subsys, &error_reason,
492 int logfile_priority;
496 if (logfile_priority < 0) {
497 error_reason =
"unknown logfile priority specified";
501 logfile_priority) < 0) {
502 error_reason =
"unable to set logfile priority";
506 else if(strcmp(key_name,
"logging.logfile_priority") == 0){
509 error_reason =
"unable to set syslog level";
516 if (strcmp (
value,
"trace") == 0) {
518 error_reason =
"unable to set debug trace";
523 if (strcmp (
value,
"on") == 0) {
525 error_reason =
"unable to set debug on";
530 if (strcmp (
value,
"off") == 0) {
532 error_reason =
"unable to set debug off";
537 error_reason =
"unknown value for debug";
545 error_reason =
"unable to set debug off";
553 *error_string = error_reason;
558static int corosync_main_config_read_logging (
559 const char **error_string)
561 const char *error_reason;
562#ifdef LOGCONFIG_USE_ICMAP
564 const char *key_name;
574 if (corosync_main_config_format_set(&error_reason) < 0) {
578 if (corosync_main_config_blackbox_set(&error_reason) < 0) {
582 if (corosync_main_config_set (
"logging", NULL, &error_reason) < 0) {
590#ifdef LOGCONFIG_USE_ICMAP
597 res = sscanf(key_name,
"logging.logger_subsys.%[^.].%s", key_subsys, key_item);
603 if (strcmp(key_item,
"subsys") != 0) {
612 error_reason =
"Can't snprintf logger_subsys key_item";
616 if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) {
620#ifdef LOGCONFIG_USE_ICMAP
633 *error_string = error_reason;
638#ifdef LOGCONFIG_USE_ICMAP
639static void main_logging_notify(
641 const char *key_name,
646static void main_logging_notify(
650 const char *key_name,
656 const char *error_string;
657 static int reload_in_progress = 0;
662 if (strcmp(key_name,
"config.reload_in_progress") == 0) {
663 if (*(uint8_t *)new_val.
data == 1) {
664 reload_in_progress = 1;
666 reload_in_progress = 0;
669 if (reload_in_progress) {
678 fprintf (stderr,
"Unable to setup logging format.\n");
680 corosync_main_config_read_logging(&error_string);
683#ifdef LOGCONFIG_USE_ICMAP
684static void add_logsys_config_notification(
void)
701static void add_logsys_config_notification(
void)
720#ifndef LOGCONFIG_USE_ICMAP
722 const char *default_logfile,
724 const char **error_string)
726 const char *error_reason = error_string_response;
728#ifndef LOGCONFIG_USE_ICMAP
730 error_reason =
"No cmap handle";
733 if (!default_logfile) {
734 error_reason =
"No default logfile";
738 main_logfile = default_logfile;
741 if (corosync_main_config_read_logging(error_string) < 0) {
742 error_reason = *error_string;
746 add_logsys_config_notification();
751 snprintf (error_string_response,
sizeof(error_string_response),
752 "parse error in config: %s.\n",
755 *error_string = error_string_response;
uint64_t cmap_iter_handle_t
#define CMAP_KEYNAME_MAXLEN
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.
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.
uint64_t cmap_track_handle_t
#define CMAP_TRACK_DELETE
cs_error_t cmap_iter_finalize(cmap_handle_t handle, cmap_iter_handle_t iter_handle)
Finalize iterator.
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.
#define CMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem....
#define CMAP_TRACK_MODIFY
#define ICMAP_TRACK_MODIFY
#define ICMAP_TRACK_DELETE
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.
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem....
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Return next item in iterator iter.
qb_map_iter_t * icmap_iter_t
Itterator type.
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
#define MAP_KEYNAME_MAXLEN
#define map_get_string(key_name, value)
int corosync_log_config_read(cmap_handle_t cmap_h, const char *default_logfile, const char **error_string)
unsigned int logsys_config_mode_get(const char *subsys)
logsys_config_mode_get
#define log_printf(level, format, args...)
int logsys_config_mode_set(const char *subsys, unsigned int mode)
logsys_config_mode_set
void logsys_blackbox_set(int enable)
char * logsys_format_get(void)
logsys_format_get
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,...
#define LOGSYS_MODE_OUTPUT_STDERR
int logsys_config_syslog_priority_set(const char *subsys, unsigned int priority)
logsys_config_syslog_priority_set
#define LOGSYS_DEBUG_TRACE
void logsys_config_apply(void)
logsys_config_apply
int logsys_priority_id_get(const char *name)
logsys_priority_id_get
int logsys_config_logfile_priority_set(const char *subsys, unsigned int priority)
logsys_config_logfile_priority_set
int logsys_config_debug_set(const char *subsys, unsigned int value)
enabling debug, disable message priority filtering.
#define LOGSYS_LEVEL_WARNING
int _logsys_subsys_create(const char *subsys, const char *filename)
_logsys_subsys_create
int logsys_config_syslog_facility_set(const char *subsys, unsigned int facility)
per system/subsystem settings.
#define LOGSYS_LEVEL_DEBUG
#define LOGSYS_MODE_OUTPUT_FILE
#define LOGSYS_MODE_OUTPUT_SYSLOG
int logsys_format_set(const char *format)
configuration bits that can only be done for the whole system
cmap_handle_t cmap_handle
Structure passed as new_value and old_value in change callback.
Structure passed as new_value and old_value in change callback.
void totemknet_configure_log_level()