Skip to content
davidmoreno edited this page May 6, 2011 · 1 revision

libonion provides several logging facilities. They are first usefull for onion debug itself, but can be used freely by the rest of onion users.

Normal use

All logging is centralized on the onion/log.h header. It provides DEBUG, WARNING and ERROR macros that call the real logger. They accept a variable number of arguments on the format of printf.

DEBUG is used only for debugging purposes and can be completely disabled at compile time, converting it an empty macro. It depends on the define DEBUG being present at log.h include time.

Available loggers

If you want to use another logger you have to do it the first on your program. Setting the onion_log variable to the function you want to use to log makes it. by default it points to onion_log_stderr which pretty prints the log messages on stderr.

Stderr logger also accept an environmental variable to change behaviour, ONION_LOG. Known possibilities are:

  • nodebug0 Removes the DEBUG0 level, and internal level for really unimportant debug messages.
  • nocolor Prints wihtout colors
  • syslog Automatically changes the logging to onion_log_syslog.

The onion_log_syslog logger logs using syslog.

Custom logger

If you want to reimplement you own logger, set onion_log to your own logger, which has to have the signature: void(* onion_log)(onion_log_level level, const char *filename, int lineno, const char *fmt,...).

Clone this wiki locally