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,
239 const char *replacement)
241 static char formatted_error_reason[128];
250 "Warning: the %s config parameter has been obsoleted." 251 " See corosync.conf man page %s directive.",
257 if (strcmp (value,
"yes") == 0 || strcmp (value,
"on") == 0) {
260 sprintf (formatted_error_reason,
"unable to set mode %s", key);
264 if (strcmp (value,
"no") == 0 || strcmp (value,
"off") == 0) {
267 sprintf (formatted_error_reason,
"unable to unset mode %s", key);
271 sprintf (formatted_error_reason,
"unknown value for %s", key);
276 else if (!subsys && !deprecated) {
286 sprintf (formatted_error_reason,
"unable to change mode %s", key);
295 *error_string = formatted_error_reason;
300 static int corosync_main_config_set (
303 const char **error_string)
305 const char *error_reason = error_string_response;
319 if (subsys != NULL) {
321 error_reason =
"unable to create new logging subsystem";
328 error_reason =
"unable to get mode";
332 if (corosync_main_config_log_destination_set (path,
"to_stderr", subsys, &error_reason,
336 if (corosync_main_config_log_destination_set (path,
"to_syslog", subsys, &error_reason,
344 syslog_facility = qb_log_facility2int(value);
345 if (syslog_facility < 0) {
346 error_reason =
"unknown syslog facility specified";
350 syslog_facility) < 0) {
351 error_reason =
"unable to set syslog facility";
360 qb_log_facility2int(
"daemon")) < 0) {
361 error_reason =
"unable to set syslog facility";
371 "Warning: the syslog_level config parameter has been obsoleted." 372 " See corosync.conf man page syslog_priority directive.");
377 if (syslog_priority < 0) {
378 error_reason =
"unknown syslog level specified";
382 syslog_priority) < 0) {
383 error_reason =
"unable to set syslog level";
394 if (syslog_priority < 0) {
395 error_reason =
"unknown syslog priority specified";
399 syslog_priority) < 0) {
400 error_reason =
"unable to set syslog priority";
407 error_reason =
"unable to set syslog level";
412 #ifdef LOGCONFIG_USE_ICMAP 428 if (corosync_main_config_log_destination_set (path,
"to_file", subsys, &error_reason,
432 if (corosync_main_config_log_destination_set (path,
"to_logfile", subsys, &error_reason,
438 int logfile_priority;
442 if (logfile_priority < 0) {
443 error_reason =
"unknown logfile priority specified";
447 logfile_priority) < 0) {
448 error_reason =
"unable to set logfile priority";
455 error_reason =
"unable to set syslog level";
462 if (strcmp (value,
"trace") == 0) {
464 error_reason =
"unable to set debug trace";
469 if (strcmp (value,
"on") == 0) {
471 error_reason =
"unable to set debug on";
476 if (strcmp (value,
"off") == 0) {
478 error_reason =
"unable to set debug off";
483 error_reason =
"unknown value for debug";
491 error_reason =
"unable to set debug off";
500 *error_string = error_reason;
505 static int corosync_main_config_read_logging (
506 const char **error_string)
508 const char *error_reason;
509 #ifdef LOGCONFIG_USE_ICMAP 511 const char *key_name;
521 if (corosync_main_config_format_set(&error_reason) < 0) {
525 if (corosync_main_config_set (
"logging", NULL, &error_reason) < 0) {
533 #ifdef LOGCONFIG_USE_ICMAP 540 res = sscanf(key_name,
"logging.logger_subsys.%[^.].%s", key_subsys, key_item);
546 if (strcmp(key_item,
"subsys") != 0) {
552 if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) {
556 #ifdef LOGCONFIG_USE_ICMAP 566 *error_string = error_reason;
571 #ifdef LOGCONFIG_USE_ICMAP 572 static void main_logging_notify(
574 const char *key_name,
579 static void main_logging_notify(
583 const char *key_name,
589 const char *error_string;
590 static int reload_in_progress = 0;
595 if (strcmp(key_name,
"config.reload_in_progress") == 0) {
596 if (*(uint8_t *)new_val.
data == 1) {
597 reload_in_progress = 1;
599 reload_in_progress = 0;
602 if (reload_in_progress) {
611 fprintf (stderr,
"Unable to setup logging format.\n");
613 corosync_main_config_read_logging(&error_string);
616 #ifdef LOGCONFIG_USE_ICMAP 617 static void add_logsys_config_notification(
void)
634 static void add_logsys_config_notification(
void)
653 #ifndef LOGCONFIG_USE_ICMAP
655 const char *default_logfile,
657 const char **error_string)
659 const char *error_reason = error_string_response;
661 #ifndef LOGCONFIG_USE_ICMAP 663 error_reason =
"No cmap handle";
666 if (!default_logfile) {
667 error_reason =
"No default logfile";
671 main_logfile = default_logfile;
674 if (corosync_main_config_read_logging(error_string) < 0) {
675 error_reason = *error_string;
679 add_logsys_config_notification();
684 snprintf (error_string_response,
sizeof(error_string_response),
685 "parse error in config: %s.\n",
688 *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
#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", ...