USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
Public Member Functions | Static Public Member Functions | List of all members
usbguard::Logger Class Reference

Logger. More...

#include <Logger.hpp>

Public Member Functions

 Logger ()
 Constructs logger with enabled log level set to warning.
 
 ~Logger ()
 Default destructor.
 
void setEnabled (bool state, LogStream::Level level=LogStream::Level::Warning)
 Enables/disables given level. More...
 
bool isEnabled (LogStream::Level level) const
 Checks if given level is enabled. More...
 
void setOutputConsole (bool state)
 Adds/deletes console output sink to/from logger sinks. More...
 
void setOutputFile (bool state, const std::string &filepath=std::string(), bool append=true)
 Adds/deletes file output sink to/from logger sinks. More...
 
void setOutputSyslog (bool state, const std::string &ident=std::string())
 Adds/deletes syslog output sink to/from logger sinks. More...
 
void setAuditFile (bool state, const std::string &filepath)
 Adds/deletes audit file output sink to/from logger sinks. More...
 
void addOutputSink (std::unique_ptr< LogSink > &sink)
 Adds given sink into logger output sinks. More...
 
void delOutputSink (const std::string &name)
 Deletes given sink from logger output sinks. More...
 
LogStream operator() (const std::string &file, int line, const std::string &function, LogStream::Level level)
 Constructs and returns new LogStream object initialized with this logger, source containing given file, line and function, and given level. More...
 
void write (const LogStream::Source &source, LogStream::Level level, const std::string &message)
 Writes information into all sinks. More...
 

Static Public Member Functions

static const std::string timestamp ()
 Generate a timestamp string. More...
 

Detailed Description

Logger.

Member Function Documentation

◆ addOutputSink()

void usbguard::Logger::addOutputSink ( std::unique_ptr< LogSink > &  sink)

Adds given sink into logger output sinks.

Parameters
sinkOutput sink to add.

◆ delOutputSink()

void usbguard::Logger::delOutputSink ( const std::string &  name)

Deletes given sink from logger output sinks.

Parameters
nameName of output sink to delete.

◆ isEnabled()

bool usbguard::Logger::isEnabled ( LogStream::Level  level) const

Checks if given level is enabled.

Internally checks whether current_level >= given_level.

Parameters
levelLog level to check.
Returns
True if given level is enabled, false otherwise.

◆ operator()()

LogStream usbguard::Logger::operator() ( const std::string &  file,
int  line,
const std::string &  function,
LogStream::Level  level 
)

Constructs and returns new LogStream object initialized with this logger, source containing given file, line and function, and given level.

Parameters
fileFile name.
lineLine number.
functionName of the function.
levelLog level.
Returns
New LogStream object.

◆ setAuditFile()

void usbguard::Logger::setAuditFile ( bool  state,
const std::string &  filepath 
)

Adds/deletes audit file output sink to/from logger sinks.

Parameters
stateIf true, then audit file output sink is added to logger output sinks, otherwise it is deleted from sinks.

◆ setEnabled()

void usbguard::Logger::setEnabled ( bool  state,
LogStream::Level  level = LogStream::Level::Warning 
)

Enables/disables given level.

Note
Default level is warning.
Parameters
stateDetermines if given level should be enabled/disabled.
levelLog level to enable/disable.

◆ setOutputConsole()

void usbguard::Logger::setOutputConsole ( bool  state)

Adds/deletes console output sink to/from logger sinks.

Parameters
stateIf true, then console output sink is added to logger output sinks, otherwise it is deleted from sinks.

◆ setOutputFile()

void usbguard::Logger::setOutputFile ( bool  state,
const std::string &  filepath = std::string(),
bool  append = true 
)

Adds/deletes file output sink to/from logger sinks.

Parameters
stateIf true, then file output sink is added to logger output sinks, otherwise it is deleted from sinks.
appendOpens file output sink in append mode.

◆ setOutputSyslog()

void usbguard::Logger::setOutputSyslog ( bool  state,
const std::string &  ident = std::string() 
)

Adds/deletes syslog output sink to/from logger sinks.

Parameters
stateIf true, then syslog output sink is added to logger output sinks, otherwise it is deleted from sinks.

◆ timestamp()

const std::string usbguard::Logger::timestamp ( )
static

Generate a timestamp string.

Format: <seconds>.<microseconds>

Returns
Timestamp string.

◆ write()

void usbguard::Logger::write ( const LogStream::Source source,
LogStream::Level  level,
const std::string &  message 
)

Writes information into all sinks.

Parameters
sourceSource.
levelLog level.
messageMessage.

The documentation for this class was generated from the following files: