autotier
Automatic Tiering Fuse Filesystem
Public Types | Public Member Functions | Private Attributes | List of all members
Logger Class Reference

Class to print logs to either stdout/stderr or the syslog. More...

#include <alert.hpp>

Public Types

enum  output_t { STD, SYSLOG }
 Whether to print to stdout/stderr or the syslog. More...
 
enum  log_level_t { NONE, NORMAL, DEBUG }
 

Public Member Functions

 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...
 

Private Attributes

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)
 

Detailed Description

Class to print logs to either stdout/stderr or the syslog.

Member Enumeration Documentation

◆ output_t

Whether to print to stdout/stderr or the syslog.

Enumerator
STD 

Print to stdout/stderr.

SYSLOG 

Print to syslog.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( log_level_t  log_level,
output_t  output = STD 
)
explicit

Construct a new Logger object.

Parameters
log_levelAssigned to log_level_
outputWhere to output, default is STD

◆ ~Logger()

Logger::~Logger ( void  )

Destroy the Logger object Close syslog if output_ == SYSLOG.

Member Function Documentation

◆ 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
msg

◆ format_bytes() [1/2]

std::string Logger::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.

Parameters
bytes
Returns
std::string

◆ 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
bytes
unit
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
msgString to print
lvlLog level to test against

◆ set_level()

void Logger::set_level ( log_level_t  log_level)

Set the log_level_ member to log_level.

Parameters
log_level_New log level

◆ 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
output

◆ 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
msgString to print

Member Data Documentation

◆ 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: