tools:logger:start
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tools:logger:start [2017/02/03 11:21] – graf | tools:logger:start [2026/04/13 11:12] (current) – [Adding Output to the SysLog] ursgraf | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Logging ====== | ====== Logging ====== | ||
| - | A logger enables a user to gather information about the state of the system at runtime. | + | A logger enables a user to gather information about the state of the system at runtime. |
| + | <code cpp> | ||
| + | Logger:: | ||
| + | Logger log = Logger:: | ||
| + | | ||
| + | log.info() << " | ||
| + | int a = 298; | ||
| + | log.warn() << "a = " << a; | ||
| + | log.error() << "first line" << endl << " | ||
| + | </ | ||
| + | A logger can log its output to one of several '' | ||
| + | While declaring a logger you can choose a category for it which is a single capital letter, see below: | ||
| + | <code cpp> | ||
| + | Logger log1 = Logger:: | ||
| + | Logger log2 = Logger:: | ||
| + | </ | ||
| + | ===== Log Levels ===== | ||
| + | A logger knows one of five severity levels. | ||
| + | * TRACE: lowest level | ||
| + | * INFO | ||
| + | * WARN | ||
| + | * ERROR | ||
| + | * FATAL: highest level | ||
| + | Every '' | ||
| + | <code cpp> | ||
| + | log.show(LogLevel:: | ||
| + | </ | ||
| + | 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 '' | ||
| + | |||
| + | ===== 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 '' | ||
| - | ===== How it works ===== | ||
| - | The most important function of the safety system is its run method. This method is called periodically by the executor. Here's how it works: | ||
| <code cpp> | <code cpp> | ||
| - | | + | |
| + | Logger log = Logger:: | ||
| + | </ | ||
| + | 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. | ||
| - | // 1) Read inputs | + | ===== Logging into the Console |
| - | for(auto ia : level-> | + | 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 |
| - | if(ia != nullptr) ia-> | + | <code cpp> |
| - | } | + | |
| - | + | ||
| - | | + | |
| - | if(level-> | + | |
| - | + | ||
| - | | + | |
| - | | + | |
| - | if(oa != nullptr) oa->set(); | + | |
| - | } | + | |
| - | } | + | |
| </ | </ | ||
| + | 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. | ||
| + | ===== Adding Output to the SysLog ===== | ||
| + | The simplest way to attach a second sink is via Logger:: | ||
| + | |||
| + | <code cpp> | ||
| + | Logger:: | ||
| + | Logger:: | ||
| + | auto log = Logger:: | ||
| + | log.show(LogLevel:: | ||
| + | </ | ||
| + | |||
| + | Alternatively, | ||
| + | call and hand it to Logger:: | ||
| + | |||
| + | <code cpp> | ||
| + | #include < | ||
| + | |||
| + | auto multi = std:: | ||
| + | multi-> | ||
| + | multi-> | ||
| + | Logger:: | ||
| + | </ | ||
| + | |||
| + | View the produced log entries in the system log with | ||
| + | <code bash> | ||
| + | $ journalctl -t myLog | ||
| + | </ | ||
tools/logger/start.1486117285.txt.gz · Last modified: (external edit)
