diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-04-15 18:31:37 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-04-15 18:43:05 +0200 |
commit | 905421aac941de7eaeb5b23a2c8742fd36f29f23 (patch) | |
tree | 36b4d2edd30c7cfd3c2b49074922bdc00f969e0d | |
parent | 19782a52e4385c03b31f6d998407ffa0c0acfa04 (diff) | |
download | embedlog-905421aac941de7eaeb5b23a2c8742fd36f29f23.tar.gz embedlog-905421aac941de7eaeb5b23a2c8742fd36f29f23.tar.bz2 embedlog-905421aac941de7eaeb5b23a2c8742fd36f29f23.zip |
limited log levels to 8 to save memory
-rw-r--r-- | include/embedlog.h | 2 | ||||
-rw-r--r-- | man/el_option.3 | 34 | ||||
-rw-r--r-- | readme.md | 2 | ||||
-rw-r--r-- | src/el-options.c | 1 | ||||
-rw-r--r-- | tst/test-el-options.c | 14 | ||||
-rw-r--r-- | tst/test-el-print.c | 4 |
6 files changed, 23 insertions, 34 deletions
diff --git a/include/embedlog.h b/include/embedlog.h index 02fe1a5..cc68043 100644 --- a/include/embedlog.h +++ b/include/embedlog.h @@ -139,8 +139,8 @@ struct el_options unsigned int print_log_level:1; unsigned int print_newline:1; unsigned int finfo:1; + unsigned int level:3; - int level; int serial_fd; int frotate_number; int fcurrent_rotate; diff --git a/man/el_option.3 b/man/el_option.3 index ae340a6..e8107a1 100644 --- a/man/el_option.3 +++ b/man/el_option.3 @@ -29,7 +29,7 @@ Value inside parenthesis determines argument types of variadic arguments sets what the current logging level shall be. Altough it accepts . B enum el_level -type, this can be whatever number from range <0, INT_MAX>. +type, this can be whatever number from range <0, 7>. The higher the level, the lower priority of the message. All messages that have lower priority (higher number) then currently set . I level @@ -54,34 +54,14 @@ There are 8 predefined levels, sorted by priority (highest first): . B EL_DBG . RE . PP -If 8 print levels are not enough, one can define new levels, knowing that -. B EL_FATAL -has int value of 0, and -. B EL_DBG -has int value of 7. -User can also use debug level and add an integer like: -. B EL_DBG -+ -. I n -- where -. I n -can be any number from range <0, INT_MAX - 8>. -. PP -If messages are printed with lower priority than -. B EL_DBG -they all will be treated as messages printed with level -. BR EL_DBG , -that means message printed with level -. B EL_DBG -and -. BR "EL_DBG + 3" , -will be printed exactly the same, so same color (if colors are enabled) and if -log level printig is enabled, such messages will have same 'd/' prefix no matter -the level. -. PP . B ERRORS . RS -Setting log level cannot fail +. B EINVAL +. RS +specified +. I level +is invalid (bigger than EL_DBG). +. RE . RE .RE .PP @@ -21,7 +21,7 @@ Implemented features are: * CLOCK_REALTIME (requires POSIX) * CLOCK_MONOTONIC (requires POSIX) * print location of printed log (file and line) -* 8 predefinied log levels and (sizeof(int) - 8) custom log levels ;-) +* 8 predefinied log levels (total rip off from syslog(2)) * colorful output (ansi colors) for easy error spotting * print memory block in wireshark-like output diff --git a/src/el-options.c b/src/el-options.c index c51608c..3c2a2d0 100644 --- a/src/el-options.c +++ b/src/el-options.c @@ -162,6 +162,7 @@ static int el_vooption { case EL_LEVEL: value_int = va_arg(ap, int); + VALID(EINVAL, value_int <= 7); options->level = value_int; return 0; diff --git a/tst/test-el-options.c b/tst/test-el-options.c index b4621e3..edf44cd 100644 --- a/tst/test-el-options.c +++ b/tst/test-el-options.c @@ -145,10 +145,18 @@ static void options_level_set(void) /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - for (i = 0; i != 32; ++i) + for (i = 0; i != 16; ++i) { - mt_fail(el_option(EL_LEVEL, i) == 0); - mt_fail(g_options.level == i); + if (i <= EL_DBG) + { + mt_fail(el_option(EL_LEVEL, i) == 0); + mt_fail(g_options.level == i); + } + else + { + mt_ferr(el_option(EL_LEVEL, i), EINVAL); + mt_fail(g_options.level == EL_DBG); + } } } diff --git a/tst/test-el-print.c b/tst/test-el-print.c index 21f3ac9..3af3e52 100644 --- a/tst/test-el-print.c +++ b/tst/test-el-print.c @@ -576,7 +576,7 @@ static void print_log_level(void) static void print_colorful_output(void) { el_option(EL_COLORS, 1); - el_option(EL_LEVEL, EL_DBG + 2); + el_option(EL_LEVEL, EL_DBG); add_log(ELF, "print_colorful_output fatal message"); add_log(ELA, "print_colorful_output alert message"); add_log(ELC, "print_colorful_output critical message"); @@ -598,7 +598,7 @@ static void print_colorful_output(void) static void print_custom_log_level(void) { el_option(EL_PRINT_LEVEL, 1); - el_option(EL_LEVEL, EL_DBG + 5); + el_option(EL_LEVEL, EL_DBG); add_log(ELD + 4, "print_custom_log_level custom debug 4"); add_log(ELD + 5, "print_custom_log_level custom debug 5"); add_log(ELD + 6, "print_custom_log_level custom debug 6"); |