diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2020-10-24 15:25:59 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2020-10-24 17:44:14 +0200 |
commit | 8135f33615d31f23f0d9ec7ef1d2778443c81cf6 (patch) | |
tree | 1e65445232ce093eee417ebdbf49e40475a39d26 /examples/print-tty.c | |
parent | 400ed4024c2a7419ae1263c1e3a75b0bfb964b0a (diff) | |
download | embedlog-8135f33615d31f23f0d9ec7ef1d2778443c81cf6.tar.gz embedlog-8135f33615d31f23f0d9ec7ef1d2778443c81cf6.tar.bz2 embedlog-8135f33615d31f23f0d9ec7ef1d2778443c81cf6.zip |
retab
no_ci
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
Diffstat (limited to 'examples/print-tty.c')
-rw-r--r-- | examples/print-tty.c | 88 |
1 files changed, 38 insertions, 50 deletions
diff --git a/examples/print-tty.c b/examples/print-tty.c index bf13440..e483c14 100644 --- a/examples/print-tty.c +++ b/examples/print-tty.c @@ -8,54 +8,42 @@ int main(void) { - /* first we nned to initialize logger to known state - */ - - el_init(); - - /* to use logger you need to enable at least one output, - * without it logs will be printed to /dev/null. Here we set - * output to serial device. - */ - - el_option(EL_OUT, EL_OUT_TTY); - - /* enbaling tty output is not enough, we still need to - * configure which device we want to use and at what speed. - * Transmission parameters are 8N1 by default. Baudrate should - * be taken from termios (3). - */ - - if (el_option(EL_TTY_DEV, "/dev/ttyUSB1", B9600) != 0) - { - perror("tty set failed"); - return 1; - } - - /* now we can simply print messages like we would do it with - * ordinary printf - we just need to log level macro as a first - * argument - */ - - el_print(ELI, "Info message"); - el_print(ELF, "Fatal message with additional argument %d", 42); - el_print(ELD, "Debug message that won't be printed due to log level"); - - /* we can change log level in runtime as we see fit, now enable - * debug prints - */ - - el_option(EL_LEVEL, EL_DBG); - el_print(ELD, "But now debug will be printed"); - - /* altough embedlog does not use dynamic allocation by itself, - * system may allocate some resources (like opened file - * descriptors when printing to file), with el_cleanup, we can - * make sure all resources are freed. In this example, this - * function will close opened tty file descriptor. - */ - - el_cleanup(); - - return 0; + /* first we nned to initialize logger to known state */ + el_init(); + + /* to use logger you need to enable at least one output, + * without it logs will be printed to /dev/null. Here we set + * output to serial device. */ + el_option(EL_OUT, EL_OUT_TTY); + + /* enbaling tty output is not enough, we still need to + * configure which device we want to use and at what speed. + * Transmission parameters are 8N1 by default. Baudrate should + * be taken from termios (3). */ + if (el_option(EL_TTY_DEV, "/dev/ttyUSB1", B9600) != 0) + { + perror("tty set failed"); + return 1; + } + + /* now we can simply print messages like we would do it with + * ordinary printf - we just need to log level macro as a first + * argument */ + el_print(ELI, "Info message"); + el_print(ELF, "Fatal message with additional argument %d", 42); + el_print(ELD, "Debug message that won't be printed due to log level"); + + /* we can change log level in runtime as we see fit, now enable + * debug prints */ + el_option(EL_LEVEL, EL_DBG); + el_print(ELD, "But now debug will be printed"); + + /* altough embedlog does not use dynamic allocation by itself, + * system may allocate some resources (like opened file + * descriptors when printing to file), with el_cleanup, we can + * make sure all resources are freed. In this example, this + * function will close opened tty file descriptor. */ + el_cleanup(); + + return 0; } |