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;
231 static int corosync_main_config_log_destination_set (
235 const char **error_string,
236 unsigned int mode_mask,
238 const char *replacement)
240 static char formatted_error_reason[128];
249 "Warning: the %s config parameter has been obsoleted." 250 " See corosync.conf man page %s directive.",
256 if (strcmp (value,
"yes") == 0 || strcmp (value,
"on") == 0) {
259 sprintf (formatted_error_reason,
"unable to set mode %s", key);
263 if (strcmp (value,
"no") == 0 || strcmp (value,
"off") == 0) {
266 sprintf (formatted_error_reason,
"unable to unset mode %s", key);
270 sprintf (formatted_error_reason,
"unknown value for %s", key);
279 *error_string = formatted_error_reason;
284 static int corosync_main_config_set (
287 const char **error_string)
289 const char *error_reason = error_string_response;
303 if (subsys != NULL) {
305 error_reason =
"unable to create new logging subsystem";
312 error_reason =
"unable to get mode";
316 if (corosync_main_config_log_destination_set (path,
"to_stderr", subsys, &error_reason,
320 if (corosync_main_config_log_destination_set (path,
"to_syslog", subsys, &error_reason,
328 syslog_facility = qb_log_facility2int(value);
329 if (syslog_facility < 0) {
330 error_reason =
"unknown syslog facility specified";
334 syslog_facility) < 0) {
335 error_reason =
"unable to set syslog facility";
347 "Warning: the syslog_level config parameter has been obsoleted." 348 " See corosync.conf man page syslog_priority directive.");
353 if (syslog_priority < 0) {
354 error_reason =
"unknown syslog level specified";
358 syslog_priority) < 0) {
359 error_reason =
"unable to set syslog level";
370 if (syslog_priority < 0) {
371 error_reason =
"unknown syslog priority specified";
375 syslog_priority) < 0) {
376 error_reason =
"unable to set syslog priority";
381 #ifdef LOGCONFIG_USE_ICMAP 397 if (corosync_main_config_log_destination_set (path,
"to_file", subsys, &error_reason,
401 if (corosync_main_config_log_destination_set (path,
"to_logfile", subsys, &error_reason,
407 int logfile_priority;
411 if (logfile_priority < 0) {
412 error_reason =
"unknown logfile priority specified";
416 logfile_priority) < 0) {
417 error_reason =
"unable to set logfile priority";
424 if (strcmp (value,
"trace") == 0) {
426 error_reason =
"unable to set debug trace";
431 if (strcmp (value,
"on") == 0) {
433 error_reason =
"unable to set debug on";
438 if (strcmp (value,
"off") == 0) {
440 error_reason =
"unable to set debug off";
445 error_reason =
"unknown value for debug";
455 *error_string = error_reason;
460 static int corosync_main_config_read_logging (
461 const char **error_string)
463 const char *error_reason;
464 #ifdef LOGCONFIG_USE_ICMAP 466 const char *key_name;
476 if (corosync_main_config_format_set(&error_reason) < 0) {
480 if (corosync_main_config_set (
"logging", NULL, &error_reason) < 0) {
488 #ifdef LOGCONFIG_USE_ICMAP 495 res = sscanf(key_name,
"logging.logger_subsys.%[^.].%s", key_subsys, key_item);
501 if (strcmp(key_item,
"subsys") != 0) {
507 if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) {
511 #ifdef LOGCONFIG_USE_ICMAP 521 *error_string = error_reason;
526 #ifdef LOGCONFIG_USE_ICMAP 527 static void main_logging_notify(
529 const char *key_name,
534 static void main_logging_notify(
538 const char *key_name,
544 const char *error_string;
545 static int reload_in_progress = 0;
550 if (strcmp(key_name,
"config.reload_in_progress") == 0) {
551 if (*(uint8_t *)new_val.
data == 1) {
552 reload_in_progress = 1;
554 reload_in_progress = 0;
557 if (reload_in_progress) {
566 fprintf (stderr,
"Unable to setup logging format.\n");
568 corosync_main_config_read_logging(&error_string);
571 #ifdef LOGCONFIG_USE_ICMAP 572 static void add_logsys_config_notification(
void)
589 static void add_logsys_config_notification(
void)
608 #ifndef LOGCONFIG_USE_ICMAP
610 const char *default_logfile,
612 const char **error_string)
614 const char *error_reason = error_string_response;
616 #ifndef LOGCONFIG_USE_ICMAP 618 error_reason =
"No cmap handle";
621 if (!default_logfile) {
622 error_reason =
"No default logfile";
626 main_logfile = default_logfile;
629 if (corosync_main_config_read_logging(error_string) < 0) {
630 error_reason = *error_string;
634 add_logsys_config_notification();
639 snprintf (error_string_response,
sizeof(error_string_response),
640 "parse error in config: %s.\n",
643 *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)
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
#define MAP_KEYNAME_MAXLEN
#define CMAP_TRACK_MODIFY
void icmap_iter_finalize(icmap_iter_t iter)
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)
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)
#define log_printf(level, format, args...)
#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)
int logsys_config_syslog_facility_set(const char *subsys, unsigned int facility)
int logsys_config_mode_set(const char *subsys, unsigned int mode)
char * logsys_format_get(void)
#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)
#define CMAP_TRACK_PREFIX
void logsys_config_apply(void)
int logsys_priority_id_get(const char *name)
uint64_t cmap_iter_handle_t
unsigned int logsys_config_mode_get(const char *subsys)
icmap_iter_t icmap_iter_init(const char *prefix)
int logsys_config_logfile_priority_set(const char *subsys, unsigned int priority)
#define LOGSYS_MODE_OUTPUT_STDERR
qb_map_iter_t * icmap_iter_t
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)
int logsys_format_set(const char *format)
#define ICMAP_TRACK_PREFIX