Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changes between Initial Version and Version 1 of Logging

2012-08-15T12:25:27Z (9 years ago)
Vojtech Horky

First version


  • Logging

    v1 v1  
     1= Logging functions in HelenOS =
     3If you want to add logging to your application, you can use already existing functions in `libc`. Currently, the implementation is trivial as the messages are only printed to the screen but using single API allows for further improvements (logging to file/over network etc.).
     5To use logging functions, include `io/log.h` and initialize the logging subsystem. After that, you can use the `log_msg` to do the logging.
     10#include <io/log.h>
     12#define NAME "myapp"
     15int main(int argc, char *argv[])
     17    log_init(NAME, LVL_NOTE);
     18    ...
     19    if (rc != EOK) {
     20        log_msg(LVL_ERROR, "Something failed (rc=%d), trying fallback...", rc);
     21        ...
     22    }
     26The first argument to `log_init` is application name, the second is the default logging level. Messages with higher level won't be printed at all.
     28`log_msg` is a `printf`-like function where first argument is level of the message (its seriousness).
     30Currently, following levels are recognised.
     32||= Name =||= Typical usage =||
     33|| `LVL_FATAL` || Fatal error, program is not able to recover at all. ||
     34|| `LVL_ERROR` || Serious error but the program can recover from it.[[BR]]E.g. driver cannot control one device but otherwise is healthy. ||
     35|| `LVL_WARN` || Easily recoverable problem, such as one corrupted packet that can be skipped. ||
     36|| `LVL_NOTE` || Notice of higher importance to the user, such as discovery of a new device. ||
     37|| `LVL_DEBUG` || Debugging-purpose message. ||
     38|| `LVL_DEBUG2` || More detailed debugging message. ||