A basic console printer with integrated logger.
More...
#include <log.h>
|
enum | level {
lALL
, lDEBUG
, lINFO
, lOUTPUT
,
lWARNING
, lERROR
, lFATAL
, lOFF
} |
| The log level. More...
|
|
|
std::ostringstream & | get (level=lOUTPUT) |
| Sets the logging level of a message. More...
|
|
| log () |
| Creates a log object. More...
|
|
| log (const log &)=delete |
|
log & | operator= (const log &)=delete |
|
A basic console printer with integrated logger.
- Note
- This is derived from the code presented in "Logging in C++" by Petru Marginean (DDJ Sep 2007)
Definition at line 31 of file log.h.
◆ level
The log level.
lDEBUG
- Only interesting for developers
lINFO
- I say something but I don't expect you to listen
lOUTPUT
- Standard program's console output
lWARNING
- I can continue but please have a look
lERROR
- Something really wrong... but you could be lucky
lFATAL
- The program cannot continue
lOFF
- Disable output
Definition at line 47 of file log.h.
◆ log()
Creates a log
object.
Definition at line 31 of file log.cc.
◆ ~log()
◆ get()
std::ostringstream & vita::log::get |
( |
level |
l = lOUTPUT | ) |
|
Sets the logging level of a message.
- Parameters
-
[in] | l | logging level of the following message |
The following code:
log().get(level) << "Hello " << username;
creates a log
object with the level
logging level, fetches its std::stringstream
object, formats and accumulates the user-supplied data and, finally:
- prints the resulting string on
std::cout
;
- persists the resulting string into the log file (if specified).
Definition at line 48 of file log.cc.
◆ setup_stream()
void vita::log::setup_stream |
( |
const std::string & |
base | ) |
|
|
static |
Sets the log::stream
variable with a convenient value.
- Parameters
-
[in] | base | base filepath of the log (e.g. /home/doe/app ) |
Given the /home/doe/app
argument associates the log::stream
variable with the app_123_18_30_00.log
file (the numbers represents the current: day of the year, hours, minutes, seconds) in the /home/doe/
directory.
Definition at line 89 of file log.cc.
◆ os
std::ostringstream vita::log::os |
|
protected |
Definition at line 65 of file log.h.
◆ reporting_level
Messages with a lower level aren't logged / printed.
Definition at line 50 of file log.h.
◆ stream
std::unique_ptr< std::ostream > vita::log::stream = nullptr |
|
static |
Optional log stream.
Definition at line 53 of file log.h.
The documentation for this class was generated from the following files: