summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-08-02 09:54:34 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-08-02 09:54:34 +0100
commita9e47c8ccb2eefbc707ee5b13dffef29cf8bdb5d (patch)
tree4fc30f934a3f27f6c3b0592ebbeaa7606e26f294
parent9acac7f9f15def92c1d10cc1a6c1ea258a1b6ca1 (diff)
downloadlibnslog-a9e47c8ccb2eefbc707ee5b13dffef29cf8bdb5d.tar.gz
libnslog-a9e47c8ccb2eefbc707ee5b13dffef29cf8bdb5d.tar.bz2
nslog: Add nslog_short_level_name() for use in renderersHEADmaster
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r--include/nslog/nslog.h11
-rw-r--r--src/core.c22
2 files changed, 33 insertions, 0 deletions
diff --git a/include/nslog/nslog.h b/include/nslog/nslog.h
index 9113527..d63ed48 100644
--- a/include/nslog/nslog.h
+++ b/include/nslog/nslog.h
@@ -48,6 +48,17 @@ typedef enum {
*/
const char *nslog_level_name(nslog_level level);
+/**
+ * Convert a logging level to a short string.
+ *
+ * The returned string is owned by the nslog library (static) and should
+ * not be freed. It will be exactly four characters wide and suitable for
+ * logging to a file neatly.
+ *
+ * \param level The level for which you want the 'short' name.
+ */
+const char *nslog_short_level_name(nslog_level level);
+
#define NSLOG_LEVEL_DD NSLOG_LEVEL_DEEPDEBUG
#define NSLOG_LEVEL_DBG NSLOG_LEVEL_DEBUG
#define NSLOG_LEVEL_CHAT NSLOG_LEVEL_VERBOSE
diff --git a/src/core.c b/src/core.c
index 132e1e6..921cb06 100644
--- a/src/core.c
+++ b/src/core.c
@@ -49,6 +49,28 @@ const char *nslog_level_name(nslog_level level)
return "**UNKNOWN**";
}
+const char *nslog_short_level_name(nslog_level level)
+{
+ switch (level) {
+ case NSLOG_LEVEL_DEEPDEBUG:
+ return "DDBG";
+ case NSLOG_LEVEL_DEBUG:
+ return "DBG ";
+ case NSLOG_LEVEL_VERBOSE:
+ return "VERB";
+ case NSLOG_LEVEL_INFO:
+ return "INFO";
+ case NSLOG_LEVEL_WARNING:
+ return "WARN";
+ case NSLOG_LEVEL_ERROR:
+ return "ERR ";
+ case NSLOG_LEVEL_CRITICAL:
+ return "CRIT";
+ };
+
+ return "?UNK";
+}
+
static void nslog__normalise_category(nslog_category_t *cat)
{