User Tools

Site Tools


tools:logger:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:logger:start [2017/02/06 08:52] – changed "LogLevel::WARN" to "LogLevel::TRACE" to show all messages gehrigtools:logger:start [2020/11/26 13:06] (current) – [Default LogWriter] ursgraf
Line 3: Line 3:
  
 <code cpp> <code cpp>
-  StreamLogWriter w(std::cout); +  Logger::setDefaultStreamLogger(std::cout); 
-  Logger log(); +  Logger log = Logger::getLogger();
-  log.set(w);+
      
   log.info() << "Logger Test";   log.info() << "Logger Test";
Line 16: Line 15:
 While declaring a logger you can choose a category for it which is a single capital letter, see below: While declaring a logger you can choose a category for it which is a single capital letter, see below:
 <code cpp> <code cpp>
-  Logger log1();      // no category +  Logger log1 = Logger::getLogger();      // no category 
-  Logger log2('A');   // category 'A', log messages will show an 'A'+  Logger log2 = Logger::getLogger('A');   // category 'A', log messages will show an 'A'
 </code> </code>
  
Line 27: Line 26:
   * ERROR   * ERROR
   * FATAL: highest level   * FATAL: highest level
-Every ''LogWriter'' can be configured to pass only log messages which have a minimum severity level. This is accomplished with+Every ''Logger'' can be configured to pass only log messages which have a minimum severity level. This is accomplished with
 <code cpp> <code cpp>
-  StreamLogWriter w(std::cout); +  log.show(LogLevel::WARN);
-  w.show(LogLevel::WARN);+
 </code> </code>
 This would enable levels WARN, ERROR and FATAL. \\ 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)''.+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)'' or use the default ''show()'' which is also ''LogLevel::TRACE''.
  
 ===== Default LogWriter ===== ===== Default LogWriter =====
Line 39: Line 37:
  
 <code cpp> <code cpp>
-  StreamLogWriter w(std::cout); +  Logger::setDefaultStreamLogger(std::cout); 
-  Logger::setDefaultWriter(&w)+  Logger log = Logger::getLogger();  // this logger will output onto the default ''LogWriter''.
-  Logger log;  // this logger will output onto the default ''LogWriter''.+
 </code> </code>
 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. 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: 
 +<code cpp>
 +  Logger::setDefaultStreamLogger(std::cout, "/tmp/log");
 +</code>
 +A log 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.
tools/logger/start.1486367529.txt.gz · Last modified: 2017/02/06 08:52 (external edit)