#include <nawa/logging/Log.h>
Public Types | |
enum class | Level { OFF , ERROR , WARNING , INFORMATIONAL , DEBUG } |
Public Member Functions | |
Log () noexcept | |
Log (std::string appname, Level level=Level::INFORMATIONAL) noexcept | |
Log (Level level) noexcept | |
Log (Log const &other) noexcept | |
Log & | operator= (Log const &other) noexcept |
virtual | ~Log () |
void | setAppname (std::string appname) noexcept |
void | setDefaultLogLevel (Level level) noexcept |
void | write (std::string const &msg) |
void | write (std::string const &msg, Level logLevel) |
void | operator() (std::string const &msg) |
void | operator() (std::string const &msg, Level logLevel) |
Static Public Member Functions | |
static void | setStream (std::ostream *os) noexcept |
static void | setOutfile (std::string const &filename) |
static void | setOutputLevel (Level level) |
static void | setExtendedFormat (bool useExtendedFormat) |
static void | lockStream () noexcept |
static bool | isLocked () noexcept |
Simple class for thread-safe logging to stderr or to any other output stream. This class uses the same ostream for logging in all instances and synchronizes the output. Every instance can have its own app name. By default, the logger will write to std::cout.
|
strong |
|
noexcept |
|
explicitnoexcept |
|
explicitnoexcept |
|
staticnoexcept |
Change the output stream to the specified one. This change will be permanent until every active Log object has been destructed. If the output stream is locked, this function will have no effect, and throw no exception (make sure to check isLocked() first).
This function is not thread-safe as long as the stream is unlocked. Please lock the stream before using the logger in a multi-threaded environment.
os | Pointer to the output stream. Make sure that this stream will be available until NAWA terminates. |
|
static |
Change the output to append to the specified log file. Will throw a nawa::Exception with error code 1 if the requested file cannot be opened for writing. This change will be permanent until every active Log object has been destructed. If the output stream is locked, this function will have no effect, and throw no exception (make sure to check isLocked() first).
This function is not thread-safe as long as the stream is unlocked. Please lock the stream before using the logger in a multi-threaded environment.
filename | Path to the log file. |
|
static |
Set the desired output log level. Only messages with a log level lower or equal the given level will be written to the output stream. Setting the output level to OFF will completely disable logging. The default output level is STANDARD. Modifying the output log level does not work while the output stream is locked, this function will have no effect then, and throw no exception (make sure to check isLocked() first).
level | Desired output log level. |
|
static |
Use systemd-style extended log messages in the format {date} {time} {hostname} {process}[{PID}]: [{appname}] {message}. If off, the format is just [{appname}] {message}. Does not work while the output stream is locked, this function will have no effect then, and throw no exception (make sure to check isLocked() first).
useExtendedFormat | Whether to use the extended format. Off by default. |
|
staticnoexcept |
Lock the output stream. It will not be possible to change the output stream of the logger anymore as long as there is at least one active Log object. If the output stream is already locked, this will have no effect. This operation is not reversible. Please run this function before multiple threads might construct Log objects, as setting the output stream/file is not thread-safe.
|
staticnoexcept |
|
noexcept |
|
noexcept |
void Log::write | ( | std::string const & | msg | ) |
void Log::write | ( | std::string const & | msg, |
Level | logLevel | ||
) |
void Log::operator() | ( | std::string const & | msg | ) |
void Log::operator() | ( | std::string const & | msg, |
Level | logLevel | ||
) |