peary::log::Log

Log of the framework to inform the user of process. More…

#include <peary/log/logging.hpp>

Public Functions

Name
Log(const Log & ) =deleteDisable copying.
Log & operator=(const Log & ) =delete
Log(Log && ) =defaultUse default move behaviour.
Log & operator=(Log && ) =default
Log()Construct a Log.
~Log()Write the output to the streams and destruct the Log.
std::ostringstream & getStream(LogLevel level =LogLevel::INFO, const std::string & file ="", const std::string & function ="", uint32_t line =0, const std::string & name ="")Gives a stream to write to using the C++ stream syntax.
std::ostringstream & getProcessStream(std::string identifier, LogLevel level =LogLevel::INFO, const std::string & file ="", const std::string & function ="", uint32_t line =0, const std::string & name ="")Gives a process stream which updates the same line as long as it is the same.
void finish()Finish the logging ensuring proper termination of all streams.
LogLevel getReportingLevel()Get the reporting level for logging.
void setReportingLevel(LogLevel level)Set a new reporting level to use for logging.
LogLevel getLevelFromString(const std::string & level)Convert a string to a LogLevel.
std::string getStringFromLevel(LogLevel level)Convert a LogLevel to a string.
LogFormat getFormat()Get the logging format.
void setFormat(LogFormat format)Set a new logging format.
LogFormat getFormatFromString(const std::string & format)Convert a string to a LogFormat.
std::string getStringFromFormat(LogFormat format)Convert a LogFormat to a string.
void addStream(std::ostream & stream)Add a stream to write the log message.
void clearStreams()Clear and delete all streams that the Log writes to.
const std::vector< std::ostream * > & getStreams()Return all the streams the Log writes to.
void setSection(std::string header)Set the section header to use from now on.
std::string getSection()Get the current section header.
std::string getTimestamp()Get the current timestamp.

Detailed Description

  class peary::log::Log;
  

Log of the framework to inform the user of process.

Should almost never be instantiated directly. The LOG macro should be used instead to pass all the information. This leads to a cleaner interface for sending log messages.

Public Functions Documentation

function Log

  Log(
    const Log & 
) =delete
  

Disable copying.

function operator=

  Log & operator=(
    const Log & 
) =delete
  

function Log

  Log(
    Log && 
) =default
  

Use default move behaviour.

function operator=

  Log & operator=(
    Log && 
) =default
  

function Log

  Log()
  

Construct a Log.

function ~Log

  ~Log()
  

Write the output to the streams and destruct the Log.

function getStream

  std::ostringstream & getStream(
    LogLevel level =LogLevel::INFO,
    const std::string & file ="",
    const std::string & function ="",
    uint32_t line =0,
    const std::string & name =""
)
  

Gives a stream to write to using the C++ stream syntax.

Parameters:

  • level Logging level
  • file The file name of the file containing the log message
  • function The function containing the log message
  • line The line number of the log message
  • name Name of the process (if any)

Return: A C++ stream to write to

function getProcessStream

  std::ostringstream & getProcessStream(
    std::string identifier,
    LogLevel level =LogLevel::INFO,
    const std::string & file ="",
    const std::string & function ="",
    uint32_t line =0,
    const std::string & name =""
)
  

Gives a process stream which updates the same line as long as it is the same.

Parameters:

  • identifier Name to indicate the line, used to distinguish when to update or write new line
  • level Logging level
  • file The file name of the file containing the log message
  • function The function containing the log message
  • line The line number of the log message
  • name Name of the process (if any)

Return: A C++ stream to write to

function finish

  static void finish()
  

Finish the logging ensuring proper termination of all streams.

function getReportingLevel

  static LogLevel getReportingLevel()
  

Get the reporting level for logging.

Return: The current log level

function setReportingLevel

  static void setReportingLevel(
    LogLevel level
)
  

Set a new reporting level to use for logging.

Parameters:

  • level The new log level

function getLevelFromString

  static LogLevel getLevelFromString(
    const std::string & level
)
  

Convert a string to a LogLevel.

Parameters:

  • level Name of the level

Return: Log level corresponding to the name

function getStringFromLevel

  static std::string getStringFromLevel(
    LogLevel level
)
  

Convert a LogLevel to a string.

Parameters:

  • level Log level

Return: Name corresponding to the log level

function getFormat

  static LogFormat getFormat()
  

Get the logging format.

Return: Current log format

function setFormat

  static void setFormat(
    LogFormat format
)
  

Set a new logging format.

Parameters:

  • format New log log format

function getFormatFromString

  static LogFormat getFormatFromString(
    const std::string & format
)
  

Convert a string to a LogFormat.

Parameters:

  • format Name of the format

Return: Log format corresponding to the name

function getStringFromFormat

  static std::string getStringFromFormat(
    LogFormat format
)
  

Convert a LogFormat to a string.

Parameters:

  • format Log format

Return: Name corresponding to the log format

function addStream

  static void addStream(
    std::ostream & stream
)
  

Add a stream to write the log message.

Parameters:

  • stream Stream to write to

function clearStreams

  static void clearStreams()
  

Clear and delete all streams that the Log writes to.

function getStreams

  static const std::vector< std::ostream * > & getStreams()
  

Return all the streams the Log writes to.

Return: List of all the streams used

function setSection

  static void setSection(
    std::string header
)
  

Set the section header to use from now on.

Parameters:

  • header Header to use

function getSection

  static std::string getSection()
  

Get the current section header.

Return: Header used

function getTimestamp

  static std::string getTimestamp()
  

Get the current timestamp.

Return: Timestamp


Updated on 2025-11-14 at 11:31:23 +0100