diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-12-05 11:38:55 +0100 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-12-05 11:38:55 +0100 |
commit | f3c138b4952d0ed709ef4235e34f749e0e31553e (patch) | |
tree | a8b4c709d2ef30abed5ac9ac84a973f7885f4834 | |
parent | eb1fcb4de62b7afe268a0dd44a5b6e2930e4053e (diff) | |
download | embedlog-f3c138b4952d0ed709ef4235e34f749e0e31553e.tar.gz embedlog-f3c138b4952d0ed709ef4235e34f749e0e31553e.tar.bz2 embedlog-f3c138b4952d0ed709ef4235e34f749e0e31553e.zip |
add: option to print to stdout
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | include/embedlog.h | 15 | ||||
-rw-r--r-- | man/el_option.3 | 5 | ||||
-rw-r--r-- | readme.md | 5 | ||||
-rw-r--r-- | src/el-options.c | 4 | ||||
-rw-r--r-- | src/el-puts.c | 7 | ||||
-rw-r--r-- | tst/test-el-options.c | 8 |
7 files changed, 37 insertions, 11 deletions
diff --git a/configure.ac b/configure.ac index 6a8c913..1ab36a0 100644 --- a/configure.ac +++ b/configure.ac @@ -75,12 +75,12 @@ AC_SUBST(COVERAGE_LDFLAGS) AC_ARG_ENABLE([out-stderr], - AS_HELP_STRING([--enable-out-stderr], [Enable printing to stderr]), + AS_HELP_STRING([--enable-out-stderr], [Enable printing to stderr and stdout]), [], [enable_out_stderr="yes"]) AS_IF([test "x$enable_out_stderr" = "xyes"], [ - AC_DEFINE([ENABLE_OUT_STDERR], [1], [Enable printing to stderr]) + AC_DEFINE([ENABLE_OUT_STDERR], [1], [Enable printing to stderr and stdout]) AC_CHECK_FUNCS([fputs],, AC_MSG_ERROR(not found, needed by --enable-out-stderr)) ]) diff --git a/include/embedlog.h b/include/embedlog.h index 5b694e6..3d67d35 100644 --- a/include/embedlog.h +++ b/include/embedlog.h @@ -65,12 +65,13 @@ enum el_output { EL_OUT_NONE = 0x0000, EL_OUT_STDERR = 0x0001, - EL_OUT_SYSLOG = 0x0002, - EL_OUT_FILE = 0x0004, - EL_OUT_NET = 0x0008, - EL_OUT_TTY = 0x0010, - EL_OUT_CUSTOM = 0x0020, - EL_OUT_ALL = 0x003f + EL_OUT_STDOUT = 0x0002, + EL_OUT_SYSLOG = 0x0004, + EL_OUT_FILE = 0x0008, + EL_OUT_NET = 0x0010, + EL_OUT_TTY = 0x0020, + EL_OUT_CUSTOM = 0x0040, + EL_OUT_ALL = 0x007f }; enum el_level @@ -142,7 +143,7 @@ typedef int (*el_custom_puts)(const char *s); struct el_options { - unsigned int outputs:6; + unsigned int outputs:7; unsigned int colors:1; unsigned int timestamp:2; unsigned int timestamp_timer:3; diff --git a/man/el_option.3 b/man/el_option.3 index 855a484..4c2ac2c 100644 --- a/man/el_option.3 +++ b/man/el_option.3 @@ -90,6 +90,11 @@ can be enabled. Messages will be printed to standard error output . RE . PP +. B EL_OUT_STDOUT +. RS +Messages will be printed to standard output +. RE +. PP . B EL_OUT_SYSLOG . RS Messages will be sent to syslog facility. This requires system with implemented @@ -14,6 +14,7 @@ Implemented features are: * syslog (very limited, works on *nuttx* for now) * directly to serial device (like /dev/ttyS0) * standard error (stderr) + * standard output (stdout) * file (with optional log rotate, and syncing to prevent data loss) * automatic file reopening on unexpected events (file deletion, SD remount) * custom routine - can be anything **embedlog** just calls custom function @@ -151,8 +152,8 @@ enable these settings later in runtime. --enable-out-stderr (default: enable) ------------------------------------- -When set, library will be able to print logs to standard error output. Nothing -fancy. +When set, library will be able to print logs to standard error output (stderr) +and standard output (stdout). Nothing fancy. --enable-out-file (default: enable) ----------------------------------- diff --git a/src/el-options.c b/src/el-options.c index a83cf66..8e0407b 100644 --- a/src/el-options.c +++ b/src/el-options.c @@ -82,6 +82,10 @@ static const int VALID_OUTS = 0 | EL_OUT_STDERR #endif +#if ENABLE_OUT_STDERR + | EL_OUT_STDOUT +#endif + #if ENABLE_OUT_SYSLOG | EL_OUT_SYSLOG #endif diff --git a/src/el-puts.c b/src/el-puts.c index 8b52c96..bfc5b8a 100644 --- a/src/el-puts.c +++ b/src/el-puts.c @@ -95,6 +95,13 @@ int el_oputs } #endif +#if ENABLE_OUT_STDERR + if (options->outputs & EL_OUT_STDOUT) + { + rv |= fputs(s, stdout) == EOF ? -1 : 0; + } +#endif + #if ENABLE_OUT_SYSLOG if (options->outputs & EL_OUT_SYSLOG) { diff --git a/tst/test-el-options.c b/tst/test-el-options.c index 880dcac..ead5593 100644 --- a/tst/test-el-options.c +++ b/tst/test-el-options.c @@ -208,6 +208,14 @@ static void options_output(void) } #endif +#ifndef ENABLE_OUT_STDERR + if (i & EL_OUT_STDOUT) + { + ok = 0; + } +#endif + + #ifndef ENABLE_OUT_SYSLOG if (i & EL_OUT_SYSLOG) { |