allpix::DefaultLogger
Logger of the framework to inform the user of process. More…
#include <log.h>
Public Functions
Name | |
---|---|
DefaultLogger(const DefaultLogger & ) =delete Disable copying. |
|
DefaultLogger & | operator=(const DefaultLogger & ) =delete Disable copying. |
DefaultLogger(DefaultLogger && ) =default Use default move behaviour. |
|
DefaultLogger & | operator=(DefaultLogger && ) =default Use default move behaviour. |
DefaultLogger() Construct a logger. |
|
~DefaultLogger() Write the output to the streams and destruct the logger. |
|
std::ostringstream & | getStream(LogLevel level =LogLevel::INFO, const std::string & file ="", const std::string & function ="", uint32_t line =0) 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) 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 logger writes to. |
const std::vector< std::ostream * > & | getStreams() Return all the streams the logger writes to. |
void | setSection(std::string header) Set the section header to use from now on. |
std::string | getSection() Get the current section header. |
void | setEventNum(uint64_t event_num) Set the current event number from now on. |
uint64_t | getEventNum() Get the current event number. |
Detailed Description
class allpix::DefaultLogger;
Logger 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 DefaultLogger
DefaultLogger(
const DefaultLogger &
) =delete
Disable copying.
function operator=
DefaultLogger & operator=(
const DefaultLogger &
) =delete
Disable copying.
function DefaultLogger
DefaultLogger(
DefaultLogger &&
) =default
Use default move behaviour.
function operator=
DefaultLogger & operator=(
DefaultLogger &&
) =default
Use default move behaviour.
function DefaultLogger
DefaultLogger()
Construct a logger.
The logger will save the number of uncaught exceptions during construction to compare that with the number of exceptions during destruction later.
function ~DefaultLogger
~DefaultLogger()
Write the output to the streams and destruct the logger.
The output is written to the streams as soon as the logger gets out-of-scope and destructed. The destructor checks specifically if an exception is thrown while output is written to the stream. In that case the log stream will not be forwarded to the output streams and the message will be discarded.
function getStream
std::ostringstream & getStream(
LogLevel level =LogLevel::INFO,
const std::string & file ="",
const std::string & function ="",
uint32_t line =0
)
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
Return: A C++ stream to write to
This method is typically automatically called by the LOG macro to return a stream after constructing the logger. The header of the stream is added before returning the output stream.
function getProcessStream
std::ostringstream & getProcessStream(
std::string identifier,
LogLevel level =LogLevel::INFO,
const std::string & file ="",
const std::string & function ="",
uint32_t line =0
)
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
Return: A C++ stream to write to
This method is typically automatically called by the LOG_PROGRESS macro. An empty identifier is the same as underscore.
function finish
static void finish()
Finish the logging ensuring proper termination of all streams.
Note: Does not close the streams
Warning: No other log message should be send after this method
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
Exceptions:
- std::invalid_argument If the string does not correspond with an existing log 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
Exceptions:
- std::invalid_argument If the string does not correspond with an existing log 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
Note: Streams cannot be individually removed at the moment and only all at once using clearStreams().
The caller has to make sure that the added ostream exists for as long log messages may be written. The std::cout stream is added automatically to the list of streams and does not need to be added itself.
function clearStreams
static void clearStreams()
Clear and delete all streams that the logger writes to.
function getStreams
static const std::vector< std::ostream * > & getStreams()
Return all the streams the logger writes to.
Return: List of all the streams used
The streams are shared by all logger instantiations.
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 setEventNum
static void setEventNum(
uint64_t event_num
)
Set the current event number from now on.
Parameters:
- event_num Event number to use
function getEventNum
static uint64_t getEventNum()
Get the current event number.
Return: Event number used
Updated on 2025-02-27 at 14:14:46 +0000