From c388b01f3c2cdaba28e58d587c1050bda135c1b5 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Wed, 25 May 2016 22:33:31 -0400 Subject: [PATCH] Provide function to convert log severity to string. --- common/tr_debug.c | 14 ++++++++++++++ include/tr_debug.h | 1 + 2 files changed, 15 insertions(+) diff --git a/common/tr_debug.c b/common/tr_debug.c index c921b8a..6981213 100644 --- a/common/tr_debug.c +++ b/common/tr_debug.c @@ -162,6 +162,20 @@ static char *join_audit_msg(const int count, char *array[]) { return buf; } +const char *sev2str(int sev) +{ + switch (sev) { + case LOG_DEBUG: return "debug"; + case LOG_INFO: return "info"; + case LOG_NOTICE: return "notice"; + case LOG_WARNING: return "warning"; + case LOG_ERR: return "err"; + case LOG_CRIT: return "crit"; + case LOG_ALERT: return "alert"; + default: return "invalid"; + } +} + int str2sev(const char* sev) { if (strcmp(sev, "debug") ==0 ) { diff --git a/include/tr_debug.h b/include/tr_debug.h index c6de406..2400ba2 100644 --- a/include/tr_debug.h +++ b/include/tr_debug.h @@ -50,6 +50,7 @@ #define tr_info(...) tr_log(LOG_INFO, __VA_ARGS__) #define tr_debug(...) tr_log(LOG_DEBUG, __VA_ARGS__) +TR_EXPORT const char *sev2str(int sev); TR_EXPORT int str2sev(const char *sev); TR_EXPORT void tr_log_threshold(const int sev); TR_EXPORT void tr_console_threshold(const int sev); -- 2.1.4