diff --git a/exec/logsys.c b/exec/logsys.c index 1430c213..26e28ee2 100644 --- a/exec/logsys.c +++ b/exec/logsys.c @@ -59,6 +59,28 @@ #include +/* similar to syslog facilities/priorities tables, + * make a tag table for internal use + */ + +#ifdef SYSLOG_NAMES +CODE tagnames[] = + { + { "log", LOGSYS_TAG_LOG }, + { "enter", LOGSYS_TAG_ENTER }, + { "leave", LOGSYS_TAG_LEAVE }, + { "trace1", LOGSYS_TAG_TRACE1 }, + { "trace2", LOGSYS_TAG_TRACE2 }, + { "trace3", LOGSYS_TAG_TRACE3 }, + { "trace4", LOGSYS_TAG_TRACE4 }, + { "trace5", LOGSYS_TAG_TRACE5 }, + { "trace6", LOGSYS_TAG_TRACE6 }, + { "trace7", LOGSYS_TAG_TRACE7 }, + { "trace8", LOGSYS_TAG_TRACE8 }, + { NULL, -1 } + }; +#endif + /* * These are not static so they can be read from the core file */ @@ -908,6 +930,30 @@ const char *logsys_priority_name_get (unsigned int priority) return (NULL); } +int logsys_tag_id_get (const char *name) +{ + unsigned int i; + + for (i = 0; tagnames[i].c_name != NULL; i++) { + if (strcasecmp(name, tagnames[i].c_name) == 0) { + return (tagnames[i].c_val); + } + } + return (-1); +} + +const char *logsys_tag_name_get (unsigned int tag) +{ + unsigned int i; + + for (i = 0; tagnames[i].c_name != NULL; i++) { + if (tag == tagnames[i].c_val) { + return (tagnames[i].c_name); + } + } + return (NULL); +} + unsigned int logsys_config_subsys_set ( const char *subsys, unsigned int tags, diff --git a/exec/mainconfig.c b/exec/mainconfig.c index 7bb4199d..efd27536 100644 --- a/exec/mainconfig.c +++ b/exec/mainconfig.c @@ -239,31 +239,14 @@ int corosync_main_config_read_logging ( char *token = strtok (value, "|"); while (token != NULL) { - if (strcmp (token, "enter") == 0) { - logsys_logger.tags |= LOGSYS_TAG_ENTER; - } else if (strcmp (token, "leave") == 0) { - logsys_logger.tags |= LOGSYS_TAG_LEAVE; - } else if (strcmp (token, "trace1") == 0) { - logsys_logger.tags |= LOGSYS_TAG_TRACE1; - } else if (strcmp (token, "trace2") == 0) { - logsys_logger.tags |= LOGSYS_TAG_TRACE2; - } else if (strcmp (token, "trace3") == 0) { - logsys_logger.tags |= LOGSYS_TAG_TRACE3; - } else if (strcmp (token, "trace4") == 0) { - logsys_logger.tags |= LOGSYS_TAG_TRACE4; - } else if (strcmp (token, "trace5") == 0) { - logsys_logger.tags |= LOGSYS_TAG_TRACE5; - } else if (strcmp (token, "trace6") == 0) { - logsys_logger.tags |= LOGSYS_TAG_TRACE6; - } else if (strcmp (token, "trace7") == 0) { - logsys_logger.tags |= LOGSYS_TAG_TRACE7; - } else if (strcmp (token, "trace8") == 0) { - logsys_logger.tags |= LOGSYS_TAG_TRACE8; - } else { + int val; + + val = logsys_tag_id_get(token); + if (val < 0) { error_reason = "bad tags value"; goto parse_error; } - + logsys_logger.tags |= val; token = strtok(NULL, "|"); } } diff --git a/include/corosync/engine/logsys.h b/include/corosync/engine/logsys.h index 77dbb08d..c901724e 100644 --- a/include/corosync/engine/logsys.h +++ b/include/corosync/engine/logsys.h @@ -119,6 +119,12 @@ extern int logsys_priority_id_get ( extern const char *logsys_priority_name_get ( unsigned int priority); +extern int logsys_tag_id_get ( + const char *name); + +extern const char *logsys_tag_name_get ( + unsigned int tag); + extern void logsys_fork_completed (void); extern void logsys_flush (void);