wiki:Logging

Version 2 (modified by Jiri Svoboda, 12 years ago) ( diff )

Better explanation of LVL_NOTE and LVL_DEBUG

Logging functions in HelenOS

If 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.).

To use logging functions, include io/log.h and initialize the logging subsystem. After that, you can use the log_msg to do the logging.

...
#include <io/log.h>

#define NAME "myapp"
...

int main(int argc, char *argv[])
{
    log_init(NAME, LVL_NOTE);
    ...
    if (rc != EOK) {
        log_msg(LVL_ERROR, "Something failed (rc=%d), trying fallback...", rc);
        ...
    }
}

The 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.

log_msg is a printf-like function where first argument is level of the message (its seriousness).

Currently, following levels are recognised.

Name Typical usage
LVL_FATAL Fatal error, program is not able to recover at all.
LVL_ERROR Serious error but the program can recover from it.
E.g. driver cannot control one device but otherwise is healthy.
LVL_WARN Easily recoverable problem, such as one corrupted packet that can be skipped.
LVL_NOTE Message that does not indicate a problem, but should be printed at the default logging level.
LVL_DEBUG Debugging-purpose message. Not printed at the default logging level. Increasing logging level to LVL_DEBUG should not swamp the log.
LVL_DEBUG2 More detailed debugging message.
Note: See TracWiki for help on using the wiki.