| 1 | = Logging functions in HelenOS = |
| 2 | |
| 3 | 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.). |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | {{{ |
| 8 | #!c |
| 9 | ... |
| 10 | #include <io/log.h> |
| 11 | |
| 12 | #define NAME "myapp" |
| 13 | ... |
| 14 | |
| 15 | int main(int argc, char *argv[]) |
| 16 | { |
| 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 | } |
| 23 | } |
| 24 | }}} |
| 25 | |
| 26 | 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. |
| 27 | |
| 28 | `log_msg` is a `printf`-like function where first argument is level of the message (its seriousness). |
| 29 | |
| 30 | Currently, following levels are recognised. |
| 31 | |
| 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. || |
| 39 | |