aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2017-08-25 12:29:12 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2017-08-25 12:29:12 +0200
commita96867011b6802e987cb221108d8a7fc43165a02 (patch)
treea834d3c7a72ef0878588b08db1967df9121aa78d
parentdf38bd24dbec2690214128fe23406c73a9c4dbee (diff)
downloadembedlog-a96867011b6802e987cb221108d8a7fc43165a02.tar.gz
embedlog-a96867011b6802e987cb221108d8a7fc43165a02.tar.bz2
embedlog-a96867011b6802e987cb221108d8a7fc43165a02.zip
Refactored log levels (now there are 8 of them instead of 4)
-rw-r--r--include/embedlog.h48
-rw-r--r--src/el-options.c2
-rw-r--r--src/el-print.c38
3 files changed, 48 insertions, 40 deletions
diff --git a/include/embedlog.h b/include/embedlog.h
index 8f9b8df..6df232c 100644
--- a/include/embedlog.h
+++ b/include/embedlog.h
@@ -12,15 +12,23 @@
#include <stdio.h>
#if NOFINFO
-# define ELE NULL, 0, EL_LEVEL_ERR
-# define ELW NULL, 0, EL_LEVEL_WRN
-# define ELI NULL, 0, EL_LEVEL_INF
-# define ELD NULL, 0, EL_LEVEL_DBG
+# define ELF NULL, 0, EL_FATAL
+# define ELA NULL, 0, EL_ALERT
+# define ELC NULL, 0, EL_CRIT
+# define ELE NULL, 0, EL_ERROR
+# define ELW NULL, 0, EL_WARN
+# define ELN NULL, 0, EL_NOTICE
+# define ELI NULL, 0, EL_INFO
+# define ELD NULL, 0, EL_DBG
#else
-# define ELE __FILE__, __LINE__, EL_LEVEL_ERR
-# define ELW __FILE__, __LINE__, EL_LEVEL_WRN
-# define ELI __FILE__, __LINE__, EL_LEVEL_INF
-# define ELD __FILE__, __LINE__, EL_LEVEL_DBG
+# define ELF __FILE__, __LINE__, EL_FATAL
+# define ELA __FILE__, __LINE__, EL_ALERT
+# define ELC __FILE__, __LINE__, EL_CRIT
+# define ELE __FILE__, __LINE__, EL_ERROR
+# define ELW __FILE__, __LINE__, EL_WARN
+# define ELN __FILE__, __LINE__, EL_NOTICE
+# define ELI __FILE__, __LINE__, EL_INFO
+# define ELD __FILE__, __LINE__, EL_DBG
#endif
#if (__STDC_VERSION__ >= 199901L)
@@ -33,20 +41,24 @@
enum el_output
{
- EL_OUT_STDERR = 0x01,
- EL_OUT_SYSLOG = 0x02,
- EL_OUT_FILE = 0x04,
- EL_OUT_NET = 0x08,
- EL_OUT_TTY = 0x10,
- EL_OUT_ALL = 0x1f
+ EL_OUT_STDERR = 0x0001,
+ EL_OUT_SYSLOG = 0x0002,
+ EL_OUT_FILE = 0x0004,
+ EL_OUT_NET = 0x0008,
+ EL_OUT_TTY = 0x0010,
+ EL_OUT_ALL = 0xffff,
};
enum el_level
{
- EL_LEVEL_ERR,
- EL_LEVEL_WRN,
- EL_LEVEL_INF,
- EL_LEVEL_DBG
+ EL_FATAL,
+ EL_ALERT,
+ EL_CRIT,
+ EL_ERROR,
+ EL_WARN,
+ EL_NOTICE,
+ EL_INFO,
+ EL_DBG
};
enum el_option
diff --git a/src/el-options.c b/src/el-options.c
index 0529f91..0ade6d7 100644
--- a/src/el-options.c
+++ b/src/el-options.c
@@ -279,7 +279,7 @@ int el_oinit
memset(options, 0, sizeof(*options));
options->print_log_level = 1;
- options->level = EL_LEVEL_INF;
+ options->level = EL_INFO;
return 0;
}
diff --git a/src/el-print.c b/src/el-print.c
index a753829..3223ebc 100644
--- a/src/el-print.c
+++ b/src/el-print.c
@@ -76,30 +76,26 @@
========================================================================== */
-static const char char_level[4] = { 'e', 'w', 'i', 'd' };
+static const char char_level[8] = { 'f', 'a', 'c', 'e', 'w', 'n', 'i', 'd' };
#if ENABLE_COLORS
/*
- * index to remove all formatting
- */
-
-
-#define COLOR_RESET 4
-
-
-/*
* colors indexes are synced with log level
*/
static const char *color[] =
{
- "\e[31m", /* red */
- "\e[33m", /* yellow */
- "\e[32m", /* green */
- "\e[34m", /* blue */
+ "\e[91m", /* fatal - light red */
+ "\e[31m", /* alert - red */
+ "\e[95m", /* critical - light magenta */
+ "\e[35m", /* error - magenta */
+ "\e[93m", /* warning - light yellow */
+ "\e[92m", /* notice - light green */
+ "\e[32m", /* information - green */
+ "\e[34m", /* debug - blue */
"\e[0m" /* remove all formats */
};
@@ -127,7 +123,7 @@ static const char *color[] =
bytes stored in buf. If colors are disabled, function will return 0 and
nothing will be stored int 'buf'.
- color can be one of log levels passed directly, or COLOR_RESET macro, which
+ color can be one of log levels passed directly, or int value 8, which
will reset colors.
========================================================================== */
@@ -136,7 +132,7 @@ static size_t el_color
(
struct el_options *options, /* options defining printing style */
char *buf, /* buffer where to store color info */
- int level /* log level or COLOR_RESET */
+ int level /* log level or 8 for reset */
)
{
#if ENABLE_COLORS
@@ -535,16 +531,16 @@ int el_ovprint
e = 0;
- if (level > EL_LEVEL_DBG)
+ if (level > EL_DBG)
{
/*
* level is larger than predefined and we don't have colors for
- * those log levels, so we force colors to be of EL_LEVEL_DBG, since
- * every level larger than EL_LEVEL_DBG is threaded as more verbose
- * debug anyway.
+ * those log levels, so we force colors to be of EL_DBG level, since
+ * every level larger than EL_DBG is threaded as more verbose debug
+ * anyway.
*/
- level = EL_LEVEL_DBG;
+ level = EL_DBG;
}
/*
@@ -595,7 +591,7 @@ int el_ovprint
* add terminal formatting reset sequence
*/
- w += el_color(options, buf + w, 4 /* COLOR_RESET */);
+ w += el_color(options, buf + w, 8 /* reset colors */);
/*
* make sure buf is always null terminated and contains new line character