Class to print logs to either stdout/stderr or the syslog.
More...
#include <alert.hpp>
|
enum | output_t { STD,
SYSLOG
} |
| Whether to print to stdout/stderr or the syslog. More...
|
|
enum | log_level_t { NONE,
NORMAL,
DEBUG
} |
|
|
| Logger (log_level_t log_level, output_t output=STD) |
| Construct a new Logger object. More...
|
|
| ~Logger (void) |
| Destroy the Logger object Close syslog if output_ == SYSLOG. More...
|
|
void | message (const std::string &msg, log_level_t lvl) const |
| Print message if lvl >= log_level_. Use this for regular informational log messages. More...
|
|
void | warning (const std::string &msg) const |
| Print message (to stderr if output_ == STD) prepended with "Warning: ". Use this for non-fatal errors. More...
|
|
void | error (const std::string &msg) const |
| Print message (to stderr if output_ == STD) prepended with "Error: ". Use this for fatal errors. More...
|
|
void | set_level (log_level_t log_level) |
| Set the log_level_ member to log_level. More...
|
|
void | set_output (output_t output) |
| Set which type of logging to do. If switching from STD to SYSLOG, open the log. If switching from SYSLOG to STD, closes log. More...
|
|
std::string | format_bytes (uintmax_t bytes) const |
| Return bytes as string in base-1024 SI units. Deprecated in favour of ffd::Bytes::get_str() from lib45d. More...
|
|
double | format_bytes (uintmax_t bytes, std::string &unit) const |
| Return bytes as double with unit returned by reference in base-1024 SI units. Only use this over ffd::Bytes::get_str() from lib45d if you're formatting a table and need the unit separate. More...
|
|
|
log_level_t | log_level_ |
| Value from config file. Each log message passes a log level to check against this number. If the message's level is higher, it is printed. More...
|
|
output_t | output_ |
| Whether to output to stdout (STD) or syslog (SYSLOG)
|
|
Class to print logs to either stdout/stderr or the syslog.
◆ output_t
Whether to print to stdout/stderr or the syslog.
Enumerator |
---|
STD | Print to stdout/stderr.
|
SYSLOG | Print to syslog.
|
◆ Logger()
Logger::Logger |
( |
log_level_t |
log_level, |
|
|
output_t |
output = STD |
|
) |
| |
|
explicit |
Construct a new Logger object.
- Parameters
-
log_level | Assigned to log_level_ |
output | Where to output, default is STD |
◆ ~Logger()
Destroy the Logger object Close syslog if output_ == SYSLOG.
◆ error()
void Logger::error |
( |
const std::string & |
msg | ) |
const |
Print message (to stderr if output_ == STD) prepended with "Error: ". Use this for fatal errors.
- Parameters
-
◆ format_bytes() [1/2]
std::string Logger::format_bytes |
( |
uintmax_t |
bytes | ) |
const |
◆ format_bytes() [2/2]
double Logger::format_bytes |
( |
uintmax_t |
bytes, |
|
|
std::string & |
unit |
|
) |
| const |
Return bytes as double with unit returned by reference in base-1024 SI units. Only use this over ffd::Bytes::get_str() from lib45d if you're formatting a table and need the unit separate.
- Parameters
-
- Returns
- double
◆ message()
void Logger::message |
( |
const std::string & |
msg, |
|
|
log_level_t |
lvl |
|
) |
| const |
Print message if lvl >= log_level_. Use this for regular informational log messages.
- Parameters
-
msg | String to print |
lvl | Log level to test against |
◆ set_level()
void Logger::set_level |
( |
log_level_t |
log_level | ) |
|
Set the log_level_ member to log_level.
- Parameters
-
◆ set_output()
void Logger::set_output |
( |
output_t |
output | ) |
|
Set which type of logging to do. If switching from STD to SYSLOG, open the log. If switching from SYSLOG to STD, closes log.
- Parameters
-
◆ warning()
void Logger::warning |
( |
const std::string & |
msg | ) |
const |
Print message (to stderr if output_ == STD) prepended with "Warning: ". Use this for non-fatal errors.
- Parameters
-
◆ log_level_
log_level_t Logger::log_level_ |
|
private |
Value from config file. Each log message passes a log level to check against this number. If the message's level is higher, it is printed.
The documentation for this class was generated from the following files: