Logs events like errors and writes them immediately to a HTML file in a human-readable format. The logger also stores the events in an internal event log to be displayed within DynExp. The class is designed such that instances can be shared between different threads. Member function calls are synchronized.
More...
|
| EventLogger () |
| Constructs the event logger without opening a log file on disk. Events are only stored in the internal log until OpenLogFile() is called to open a log file on disk. More...
|
|
| EventLogger (std::string Filename) |
| Constructs the event logger with opening a log file on disk. More...
|
|
| ~EventLogger () |
| Destructor closes the log file on disk. More...
|
|
void | OpenLogFile (std::string Filename) |
| Opens the HTML log file on disk. If it already exists, the file gets overwritten. More...
|
|
void | CloseLogFile () |
| Closes the log file on disk and writes terminating HTML tags. More...
|
|
bool | IsOpen () const |
| Determines whether the log file has been openend on disk. More...
|
|
std::string | GetLogFilename () const |
| Determines the full file path to the currently openend log file. More...
|
|
void | ClearLog () |
| Clears the internal event log. More...
|
|
std::vector< LogEntry > | GetLog (size_t FirstElement=0) const |
| Returns the internal event log starting from the n-th stored element. More...
|
|
auto | GetLogSize () const |
| Determines the number of entries in the internal event log. More...
|
|
|
These functions do not throw exceptions. Instead, they do not perform logging if an exception occurs. This ensures that catching and logging exceptions does not possibly cause itself an exception which propagates through functions meant to be noexcept by catching and logging exceptions occurring within.
|
void | Log (const std::string &Message, const ErrorType Type=ErrorType::Info, const size_t Line=0, const std::string &Function="", const std::string &File="", const int ErrorCode=0, const std::stacktrace &Trace={}) noexcept |
| Logs an event from information specified manually. More...
|
|
void | Log (const Exception &E) noexcept |
| Logs a DynExp exception. More...
|
|
void | Log (const Warning &W) noexcept |
| Logs a warning. More...
|
|
| INonCopyable (const INonCopyable &)=delete |
|
INonCopyable & | operator= (const INonCopyable &)=delete |
|
|
static std::string | FormatLog (const std::string &Message, const size_t Line=0, const std::string &Function="", const std::string &Filename="", const int ErrorCode=0, const bool PrefixMessage=true) |
| Formats a log entry as plain text to be displayed within DynExp. More...
|
|
static std::string | FormatLogHTML (const std::string &Message, const ErrorType Type=ErrorType::Info, const size_t Line=0, const std::string &Function="", const std::string &Filename="", const int ErrorCode=0, const std::stacktrace &Trace={}) |
| Formats a log entry as HTML code to be displayed in a web browser. More...
|
|
|
|
These functions are not thread-safe. To be called from thread-safe functions only. Thread-safe functions must only call unsafe (private) functions.
|
bool | IsOpenUnsafe () const |
|
void | CloseLogFileUnsafe () |
|
void | ClearLogUnsafe () |
|
|
static constexpr auto | LogOperationTimeout = std::chrono::milliseconds(100) |
| Internal timeout for locking the mutex which synchronizes the calls to member function calls. If the timeout is exceeded while locking the mutex to log an event, the event is not logged. More...
|
|
Logs events like errors and writes them immediately to a HTML file in a human-readable format. The logger also stores the events in an internal event log to be displayed within DynExp. The class is designed such that instances can be shared between different threads. Member function calls are synchronized.
Definition at line 1060 of file Util.h.
◆ EventLogger() [1/2]
Util::EventLogger::EventLogger |
( |
| ) |
|
Constructs the event logger without opening a log file on disk. Events are only stored in the internal log until OpenLogFile() is called to open a log file on disk.
Definition at line 304 of file Util.cpp.
◆ EventLogger() [2/2]
Util::EventLogger::EventLogger |
( |
std::string |
Filename | ) |
|
|
inline |
Constructs the event logger with opening a log file on disk.
- Parameters
-
Filename | Name and path of the HTML log file to write the events to |
Definition at line 1073 of file Util.h.
◆ ~EventLogger()
Util::EventLogger::~EventLogger |
( |
| ) |
|
|
inline |
Destructor closes the log file on disk.
Definition at line 1078 of file Util.h.
◆ ClearLog()
void Util::EventLogger::ClearLog |
( |
| ) |
|
|
inline |
Clears the internal event log.
Definition at line 1174 of file Util.h.
◆ ClearLogUnsafe()
void Util::EventLogger::ClearLogUnsafe |
( |
| ) |
|
|
inlineprivate |
◆ CloseLogFile()
void Util::EventLogger::CloseLogFile |
( |
| ) |
|
|
inline |
Closes the log file on disk and writes terminating HTML tags.
Definition at line 1157 of file Util.h.
◆ CloseLogFileUnsafe()
void Util::EventLogger::CloseLogFileUnsafe |
( |
| ) |
|
|
private |
◆ FormatLog()
std::string Util::EventLogger::FormatLog |
( |
const std::string & |
Message, |
|
|
const size_t |
Line = 0 , |
|
|
const std::string & |
Function = "" , |
|
|
const std::string & |
Filename = "" , |
|
|
const int |
ErrorCode = 0 , |
|
|
const bool |
PrefixMessage = true |
|
) |
| |
|
static |
Formats a log entry as plain text to be displayed within DynExp.
- Parameters
-
Message | Message string describing the reason and consequences of the message |
Line | Line in source code where the message occurred |
Function | Function in source code where the message occurred |
Filename | Source code file where the message occurred |
ErrorCode | DynExp error code from DynExpErrorCodes::DynExpErrorCodes |
PrefixMessage | If true or Filename or Function are not empty, Message is prepended by a colon. |
- Returns
- Returns the formatted log entry.
Definition at line 365 of file Util.cpp.
◆ FormatLogHTML()
std::string Util::EventLogger::FormatLogHTML |
( |
const std::string & |
Message, |
|
|
const ErrorType |
Type = ErrorType::Info , |
|
|
const size_t |
Line = 0 , |
|
|
const std::string & |
Function = "" , |
|
|
const std::string & |
Filename = "" , |
|
|
const int |
ErrorCode = 0 , |
|
|
const std::stacktrace & |
Trace = {} |
|
) |
| |
|
static |
Formats a log entry as HTML code to be displayed in a web browser.
- Parameters
-
Message | Message string describing the reason and consequences of the message |
Type | DynExp error type from Util::ErrorType |
Line | Line in source code where the message occurred |
Function | Function in source code where the message occurred |
Filename | Source code file where the message occurred |
ErrorCode | DynExp error code from DynExpErrorCodes::DynExpErrorCodes |
Trace | Stack trace object created where the message occurred. If it contains entries, they are displayed in an accordion-like style. |
- Returns
- Returns the formatted log entry.
Definition at line 390 of file Util.cpp.
◆ GetLog()
std::vector< LogEntry > Util::EventLogger::GetLog |
( |
size_t |
FirstElement = 0 | ) |
const |
Returns the internal event log starting from the n-th stored element.
- Parameters
-
FirstElement | n-th element from which the returned event log starts |
- Returns
- Event log as a vector of log entries of type Util::LogEntry
- Exceptions
-
Definition at line 486 of file Util.cpp.
◆ GetLogFilename()
std::string Util::EventLogger::GetLogFilename |
( |
| ) |
const |
|
inline |
Determines the full file path to the currently openend log file.
- Returns
- Path to the openend log file. Empty string if the log file is not opened.
Definition at line 1169 of file Util.h.
◆ GetLogSize()
auto Util::EventLogger::GetLogSize |
( |
| ) |
const |
|
inline |
Determines the number of entries in the internal event log.
- Returns
- Number of events stored in the event log
Definition at line 1188 of file Util.h.
◆ IsOpen()
bool Util::EventLogger::IsOpen |
( |
| ) |
const |
|
inline |
Determines whether the log file has been openend on disk.
- Returns
- True if the log file is opened, false otherwise.
Definition at line 1163 of file Util.h.
◆ IsOpenUnsafe()
bool Util::EventLogger::IsOpenUnsafe |
( |
| ) |
const |
|
inlineprivate |
◆ Log() [1/3]
void Util::EventLogger::Log |
( |
const Exception & |
E | ) |
|
|
noexcept |
Logs a DynExp exception.
- Parameters
-
Definition at line 342 of file Util.cpp.
◆ Log() [2/3]
void Util::EventLogger::Log |
( |
const std::string & |
Message, |
|
|
const ErrorType |
Type = ErrorType::Info , |
|
|
const size_t |
Line = 0 , |
|
|
const std::string & |
Function = "" , |
|
|
const std::string & |
File = "" , |
|
|
const int |
ErrorCode = 0 , |
|
|
const std::stacktrace & |
Trace = {} |
|
) |
| |
|
noexcept |
Logs an event from information specified manually.
- Parameters
-
Message | Message string describing the reason and consequences of the message |
Type | DynExp error type from Util::ErrorType |
Line | Line in source code where the message occurred |
Function | Function in source code where the message occurred |
File | Source code file where the message occurred |
ErrorCode | DynExp error code from DynExpErrorCodes::DynExpErrorCodes |
Trace | Stack trace object created where the message occurred. |
Definition at line 309 of file Util.cpp.
◆ Log() [3/3]
void Util::EventLogger::Log |
( |
const Warning & |
W | ) |
|
|
noexcept |
Logs a warning.
- Parameters
-
Definition at line 351 of file Util.cpp.
◆ OpenLogFile()
void Util::EventLogger::OpenLogFile |
( |
std::string |
Filename | ) |
|
Opens the HTML log file on disk. If it already exists, the file gets overwritten.
- Parameters
-
Filename | Name and path of the HTML log file to write the events to. |
Definition at line 446 of file Util.cpp.
◆ Filename
std::string Util::EventLogger::Filename |
|
private |
Filename and path to the log file on disk.
Definition at line 1208 of file Util.h.
◆ LogEntries
std::vector<LogEntry> Util::EventLogger::LogEntries |
|
private |
Internally stored log entries.
Definition at line 1210 of file Util.h.
◆ LogFile
std::ofstream Util::EventLogger::LogFile |
|
private |
Stream object to write to the log file on disk.
Definition at line 1207 of file Util.h.
◆ LogOperationTimeout
constexpr auto Util::EventLogger::LogOperationTimeout = std::chrono::milliseconds(100) |
|
staticconstexprprivate |
Internal timeout for locking the mutex which synchronizes the calls to member function calls. If the timeout is exceeded while locking the mutex to log an event, the event is not logged.
Definition at line 1205 of file Util.h.
The documentation for this class was generated from the following files: