# Real-Time Robotics Framework

### Sidebar

tools:logger:start

# Logging

A logger enables a user to gather information about the state of the system at runtime. A logger can be declared and used as follows:

  StreamLogWriter w(std::cout);
Logger log;
log.set(w);

log.info() << "Logger Test";
int a = 298;
log.warn() << "a = " << a;
log.error() << "first line" << endl << "second line"; 

A logger can log its output to one of several LogWriters. Currently we support a StreamLogWriter which writes to the console and a SysLogWriter which writes into to system log file (on UNIX-Systems).
While declaring a logger you can choose a category for it which is a single capital letter, see below:

  Logger log1();      // no category
Logger log2('A');   // category 'A', log messages will show an 'A'

## Log Levels

A logger knows one of five severity levels.

• TRACE: lowest level
• INFO
• WARN
• ERROR
• FATAL: highest level

Every LogWriter can be configured to pass only log messages which have a minimum severity level. This is accomplished with

  StreamLogWriter w(std::cout);
w.show(LogLevel::WARN);

This would enable levels WARN, ERROR and FATAL.
If you do not specify a certain level the default level is INFO. If you want to see all messages you have to use show(LogLevel::TRACE).

## Default LogWriter

The EEROS library itself used several loggers, e.g. the safety system and the executor both log certain states and transitions. In order to see those generated messages it is necessary to specify a default LogWriter. This default channel will take care of all the loggers in the library as well as user defined loggers, which do not have a specifically assigned LogWriter to it.

  StreamLogWriter w(std::cout);
Logger::setDefaultWriter(&w);
Logger log;  // this logger will output onto the default ''LogWriter''.

If you forget to assign a default logger, you will not get logging information from components of the library such as the safety system or the executor.

## Logging into the Console and into a File

Sometimes it can be desirable to have a logger write to the console and write the same content into a file. This is especially helpful on a embedded system where you start an application remotely (e.g. through ssh). In such a case you can define a StreamLogWriter as follows:

  StreamLogWriter w(std::cout, "/tmp/log");

A lop file will be created at the given location. Its file name will be appended with the current date and time of the creation of the file. That is the creation of the StreamLogWriter object.