[Olsr-dev] How to enable logging in olsr2?

Henning Rogge (spam-protected)
Mon May 27 09:31:52 CEST 2013

On 05/25/2013 04:45 PM, Benjamin Valentin wrote:
> Hi,
> what is required to enable oonf_api logging to stderr/syslog and
> setting a log level from within the code?

A good question, time for another mail to explain things about Olsrd2..
(sending this to the olsr-dev list too).

I just pushed some cleanup to the logging system, so please run a "git 
pull" on both repositories.

The OONF-Logging System

The OONF-api currently use a logging system with three log severities 
(debug, info, warning) and a large number of logging sources. Each of 
these logging sources can be set to log only warnings, warnings and info 
messages or all logging messages.

Default behavior is to log all warnings.

In addition to logging sources the OONF-api use logging "handlers" as 
consumers of logging messages. There can be multiple handlers at the 
same time and they can be changed even at runtime (through a plugin for 

Each plugin can define additional logging sources, normally they should 
use the plugin name as the logging source name (if they use one at all).

There are three logging handlers directly implemented in the oonf-api, 
"stderr", "syslog" and "file". Default logging handler is "stderr".

Configuration of the Logging System

The logging system is configured in a section called "log". Run "olsrd2 
--schema" to get a list of all configuration sections.

The logging system uses five entries in 'log', two for defining logging 
sources, three for activating logging handlers. Run "olsrd2 
--schema=log" to see the configuration entries in 'log'.

"debug" and "info" are lists, which mean they can be used multiple 
times. Each value activates a single logging source for debug/info 
level, warnings are always active. Run "olsrd2 --schema=log.debug" or 
"olsrd2 --schema=log.info" to get a list of all logging sources. The 
source "all" is a combination of all logging sources.

Example configuration file

debug  os_routing
info   http
syslog true

This example activates debug, info and warning messages for the 
'os_routing' source and info/warnings for the 'http' source. It also 
activates the 'syslog' handler.

Example configuration by parameters

./olsrd2 --set log.debug=os_routing --set log.info=http --set 

This command line triggers exactly the same configuration options as the 
configuration file shown above.

You can mix both configuration file and command line options.

How to generate logging output in the code

There are three macros to generate logging output (OONF_DEBUG, OONF_INFO 
and OONF_WARN). All of them take a logging source (an 'enum 
oonf_log_source') as the first parameter, the rest of the parameters are 
the same as the printf() call. The macros also add a '\n' at the end if 
your output string does not end with one.

OONF_DEBUG(LOG_TIMER, "Timer %s expired!", timer->name);

Henning Rogge

Diplom-Informatiker Henning Rogge , Fraunhofer-Institut für
Kommunikation, Informationsverarbeitung und Ergonomie FKIE
Kommunikationssysteme (KOM)
Fraunhofer Straße 20, 53343 Wachtberg, Germany
Telefon +49 228 9435-961,   Fax +49 228 9435 685
mailto:(spam-protected) http://www.fkie.fraunhofer.de

More information about the Olsr-dev mailing list