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)
56static char error_string_response[512];
79static 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 )) {
133static int corosync_main_config_format_set (
134 const char **error_string)
136 const char *error_reason;
137 char new_format_buffer[PATH_MAX];
140 char timestamp_str_to_add[8];
143 if (strcmp (
value,
"on") == 0) {
144 if (!insert_into_buffer(new_format_buffer,
145 sizeof(new_format_buffer),
149 if (!insert_into_buffer(new_format_buffer,
150 sizeof(new_format_buffer),
155 if (strcmp (
value,
"off") == 0) {
158 error_reason =
"unknown value for fileline";
167 error_reason =
"not enough memory to set logging format buffer";
172 if (strcmp (
value,
"on") == 0) {
173 if (!insert_into_buffer(new_format_buffer,
174 sizeof(new_format_buffer),
178 if (!insert_into_buffer(new_format_buffer,
179 sizeof(new_format_buffer),
184 if (strcmp (
value,
"off") == 0) {
187 error_reason =
"unknown value for function_name";
196 error_reason =
"not enough memory to set logging format buffer";
200 memset(timestamp_str_to_add, 0,
sizeof(timestamp_str_to_add));
203 if (strcmp (
value,
"on") == 0) {
204 strcpy(timestamp_str_to_add,
"%t");
205#ifdef QB_FEATURE_LOG_HIRES_TIMESTAMPS
206 }
else if (strcmp (
value,
"hires") == 0) {
207 strcpy(timestamp_str_to_add,
"%T");
209 }
else if (strcmp (
value,
"off") == 0) {
212 error_reason =
"unknown value for timestamp";
222#ifdef QB_FEATURE_LOG_HIRES_TIMESTAMPS
223 strcpy(timestamp_str_to_add,
"%T");
225 strcpy(timestamp_str_to_add,
"%t");
229 if(strcmp(timestamp_str_to_add,
"") != 0) {
230 strcat(timestamp_str_to_add,
" ");
231 if (insert_into_buffer(new_format_buffer,
sizeof(new_format_buffer),
232 timestamp_str_to_add, NULL) == 0) {
238 error_reason =
"not enough memory to set logging format buffer";
245 *error_string = error_reason;
254static int corosync_main_config_blackbox_set (
255 const char **error_string)
257 const char *error_reason;
261 if (strcmp (
value,
"on") == 0) {
263 }
else if (strcmp (
value,
"off") == 0) {
266 error_reason =
"unknown value for blackbox";
279 *error_string = error_reason;
284static int corosync_main_config_log_destination_set (
288 const char **error_string,
289 unsigned int mode_mask,
292 const char *replacement)
294 static char formatted_error_reason[128];
303 "Warning: the %s config parameter has been obsoleted."
304 " See corosync.conf man page %s directive.",
310 if (strcmp (
value,
"yes") == 0 || strcmp (
value,
"on") == 0) {
313 sprintf (formatted_error_reason,
"unable to set mode %s", key);
317 if (strcmp (
value,
"no") == 0 || strcmp (
value,
"off") == 0) {
320 sprintf (formatted_error_reason,
"unable to unset mode %s", key);
324 sprintf (formatted_error_reason,
"unknown value for %s", key);
329 else if (!subsys && !deprecated) {
339 sprintf (formatted_error_reason,
"unable to change mode %s", key);
348 *error_string = formatted_error_reason;
353static int corosync_main_config_set (
356 const char **error_string)
358 const char *error_reason = error_string_response;
372 if (subsys != NULL) {
374 error_reason =
"unable to create new logging subsystem";
381 error_reason =
"unable to get mode";
385 if (corosync_main_config_log_destination_set (path,
"to_stderr", subsys, &error_reason,
389 if (corosync_main_config_log_destination_set (path,
"to_syslog", subsys, &error_reason,
397 syslog_facility = qb_log_facility2int(
value);
398 if (syslog_facility < 0) {
399 error_reason =
"unknown syslog facility specified";
403 syslog_facility) < 0) {
404 error_reason =
"unable to set syslog facility";
413 qb_log_facility2int(
"daemon")) < 0) {
414 error_reason =
"unable to set syslog facility";
424 "Warning: the syslog_level config parameter has been obsoleted."
425 " See corosync.conf man page syslog_priority directive.");
430 if (syslog_priority < 0) {
431 error_reason =
"unknown syslog level specified";
435 syslog_priority) < 0) {
436 error_reason =
"unable to set syslog level";
447 if (syslog_priority < 0) {
448 error_reason =
"unknown syslog priority specified";
452 syslog_priority) < 0) {
453 error_reason =
"unable to set syslog priority";
457 else if(strcmp(key_name,
"logging.syslog_priority") == 0){
460 error_reason =
"unable to set syslog level";
465#ifdef LOGCONFIG_USE_ICMAP
481 if (corosync_main_config_log_destination_set (path,
"to_file", subsys, &error_reason,
485 if (corosync_main_config_log_destination_set (path,
"to_logfile", subsys, &error_reason,
491 int logfile_priority;
495 if (logfile_priority < 0) {
496 error_reason =
"unknown logfile priority specified";
500 logfile_priority) < 0) {
501 error_reason =
"unable to set logfile priority";
505 else if(strcmp(key_name,
"logging.logfile_priority") == 0){
508 error_reason =
"unable to set syslog level";
515 if (strcmp (
value,
"trace") == 0) {
517 error_reason =
"unable to set debug trace";
522 if (strcmp (
value,
"on") == 0) {
524 error_reason =
"unable to set debug on";
529 if (strcmp (
value,
"off") == 0) {
531 error_reason =
"unable to set debug off";
536 error_reason =
"unknown value for debug";
544 error_reason =
"unable to set debug off";
552 *error_string = error_reason;
557static int corosync_main_config_read_logging (
558 const char **error_string)
560 const char *error_reason;
561#ifdef LOGCONFIG_USE_ICMAP
563 const char *key_name;
573 if (corosync_main_config_format_set(&error_reason) < 0) {
577 if (corosync_main_config_blackbox_set(&error_reason) < 0) {
581 if (corosync_main_config_set (
"logging", NULL, &error_reason) < 0) {
589#ifdef LOGCONFIG_USE_ICMAP
596 res = sscanf(key_name,
"logging.logger_subsys.%[^.].%s", key_subsys, key_item);
602 if (strcmp(key_item,
"subsys") != 0) {
611 error_reason =
"Can't snprintf logger_subsys key_item";
615 if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) {
619#ifdef LOGCONFIG_USE_ICMAP
629 *error_string = error_reason;
634#ifdef LOGCONFIG_USE_ICMAP
635static void main_logging_notify(
637 const char *key_name,
642static void main_logging_notify(
646 const char *key_name,
652 const char *error_string;
653 static int reload_in_progress = 0;
658 if (strcmp(key_name,
"config.reload_in_progress") == 0) {
659 if (*(uint8_t *)new_val.
data == 1) {
660 reload_in_progress = 1;
662 reload_in_progress = 0;
665 if (reload_in_progress) {
674 fprintf (stderr,
"Unable to setup logging format.\n");
676 corosync_main_config_read_logging(&error_string);
679#ifdef LOGCONFIG_USE_ICMAP
680static void add_logsys_config_notification(
void)
697static void add_logsys_config_notification(
void)
716#ifndef LOGCONFIG_USE_ICMAP
718 const char *default_logfile,
720 const char **error_string)
722 const char *error_reason = error_string_response;
724#ifndef LOGCONFIG_USE_ICMAP
726 error_reason =
"No cmap handle";
729 if (!default_logfile) {
730 error_reason =
"No default logfile";
734 main_logfile = default_logfile;
737 if (corosync_main_config_read_logging(error_string) < 0) {
738 error_reason = *error_string;
742 add_logsys_config_notification();
747 snprintf (error_string_response,
sizeof(error_string_response),
748 "parse error in config: %s.\n",
751 *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.