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...
#include <Util.h>
|
| | ~EventLogger () |
| | Destructor closes the log file on disk.
|
| |
| void | OpenLogFile (std::string Filename) |
| | Opens the HTML log file on disk. If it already exists, the file gets overwritten.
|
| |
| void | CloseLogFile () |
| | Closes the log file on disk and writes terminating HTML tags.
|
| |
| bool | IsOpen () const |
| | Determines whether the log file has been openend on disk.
|
| |
| std::string | GetLogFilename () const |
| | Determines the full file path to the currently openend log file.
|
| |
| void | ClearLog () |
| | Clears the internal event log.
|
| |
| std::vector< LogEntry > | GetLog (size_t FirstElement=0) const |
| | Returns the internal event log starting from the n-th stored element.
|
| |
| auto | GetLogSize () const |
| | Determines the number of entries in the internal event log.
|
| |
|
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.
|
| |
| void | Log (const Exception &E) noexcept |
| | Logs a DynExp exception.
|
| |
| void | Log (const Warning &W) noexcept |
| | Logs a warning.
|
| |
| | 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.
|
| |
| 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.
|
| |
|
| | 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.
|
| |
| | EventLogger (std::string Filename) |
| | Constructs the event logger with opening a log file on disk.
|
| |
|
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 () |
| |
|
| std::ofstream | LogFile |
| | Stream object to write to the log file on disk.
|
| |
| std::string | Filename |
| | Filename and path to the log file on disk.
|
| |
| std::vector< LogEntry > | LogEntries |
| | Internally stored log entries.
|
| |
|
| 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.
|
| |
|
| EventLogger & | EventLog () |
| | This function holds a static EventLogger instance and returns a reference to it. DynExp uses only one EventLogger instance to log events from any thread. A local static object instead of a global object is employed to avoid initialization order problems.
|
| |
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 1120 of file Util.h.
◆ EventLogger() [1/2]
| Util::EventLogger::EventLogger |
( |
| ) |
|
|
private |
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 312 of file Util.cpp.
◆ EventLogger() [2/2]
| Util::EventLogger::EventLogger |
( |
std::string |
Filename | ) |
|
|
inlineprivate |
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 1134 of file Util.h.
◆ ~EventLogger()
| Util::EventLogger::~EventLogger |
( |
| ) |
|
|
inline |
Destructor closes the log file on disk.
Definition at line 1140 of file Util.h.
◆ ClearLog()
| void Util::EventLogger::ClearLog |
( |
| ) |
|
|
inline |
Clears the internal event log.
Definition at line 1236 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 1219 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 373 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 398 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 494 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 1231 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 1250 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 1225 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 350 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 317 of file Util.cpp.
◆ Log() [3/3]
| void Util::EventLogger::Log |
( |
const Warning & |
W | ) |
|
|
noexcept |
Logs a warning.
- Parameters
-
Definition at line 359 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 454 of file Util.cpp.
◆ EventLog
This function holds a static EventLogger instance and returns a reference to it. DynExp uses only one EventLogger instance to log events from any thread. A local static object instead of a global object is employed to avoid initialization order problems.
- Returns
- Reference to DynExp's unique EventLogger instance
Definition at line 517 of file Util.cpp.
◆ Filename
| std::string Util::EventLogger::Filename |
|
private |
Filename and path to the log file on disk.
Definition at line 1270 of file Util.h.
◆ LogEntries
| std::vector<LogEntry> Util::EventLogger::LogEntries |
|
private |
Internally stored log entries.
Definition at line 1272 of file Util.h.
◆ LogFile
| std::ofstream Util::EventLogger::LogFile |
|
private |
Stream object to write to the log file on disk.
Definition at line 1269 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 1267 of file Util.h.
The documentation for this class was generated from the following files: