|
Core Library
1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
|
#include <DebugLog.h>
Public Member Functions | |
| DebugLog ()=default | |
| Default constructor. More... | |
| DebugLog (const std::string &softwareVersion, const std::string &logFolderPath, const std::string &logName, long maxLogSize=5 *BYTES_IN_MEBIBYTE) | |
| Initialisation constructor. More... | |
| DebugLog (const DebugLog &)=delete | |
| Copy constructor deleted. | |
| DebugLog & | operator= (const DebugLog &)=delete |
| Copy assignment operator deleted. | |
| DebugLog (DebugLog &&)=delete | |
| Move constructor deleted. | |
| DebugLog & | operator= (DebugLog &&)=delete |
| Move assignment operator deleted. | |
| ~DebugLog () | |
| Destructor. | |
| void | Instantiate (const std::string &softwareVersion, const std::string &logFolderPath, const std::string &logName, long maxLogSize=5 *BYTES_IN_MEBIBYTE) |
| Instantiate a previously default constructed DebugLog object. More... | |
| void | AddLogMsgLevelFilter (eLogMessageLevel logMessageLevel) |
| Add level to filter. More... | |
| void | RemoveLogMsgLevelFilter (eLogMessageLevel logMessageLevel) |
| Remove level from filter. More... | |
| void | ClearLogMsgLevelFilters () |
| Clear all message levels from filter. More... | |
| void | AddLogMessage (const std::string &message) |
| Add message to the log file. More... | |
| void | AddLogMessage (const std::string &message, const std::string &file, const std::string &function, int lineNo, eLogMessageLevel logMsgLevel) |
| Add message to the log file. More... | |
Private Types | |
| enum | eFileOpenOptions { truncate_file, append_file } |
| Enumeration containing file opening options. More... | |
| using | log_msg_queue = threads::MessageQueueThread< int, dl_private::LogQueueMessage > |
| Typedef for message queue thread. | |
Private Member Functions | |
| long | MaxLogSize () const |
| Get the max log size in bytes. | |
| void | RegisterLogQueueMessageId () |
| Register the log queue message ID. | |
| bool | MessageHandler (dl_private::LogQueueMessage &message) |
| Method to process message. More... | |
| bool | IsLogMsgLevelInLookup (eLogMessageLevel logMessageLevel) const |
| Is message level in map. More... | |
| const std::string & | GetLogMsgLevelAsString (eLogMessageLevel logMessageLevel) const |
| Get message level as a string. More... | |
| bool | IsLogMsgLevelFilterSetNoMutex (eLogMessageLevel logMessageLevel) const |
| Is message level in filter set (no mutex). More... | |
| bool | IsLogMsgLevelFilterSet (eLogMessageLevel logMessageLevel) const |
| Is message level in filter set (with mutex). More... | |
| void | OpenOfStream (const std::string &filePath, eFileOpenOptions fileOptions) |
| Open file stream. More... | |
| void | CloseOfStream () |
| Close file stream. | |
| void | CheckLogFileSize (long requiredSpace) |
| Check size of current log file. More... | |
| void | WriteMessageToLog (dl_private::LogQueueMessage &&logMessage) |
| Write log message to file stream. More... | |
Static Private Member Functions | |
| static int | MessageDecoder (const dl_private::LogQueueMessage &) |
| Method to decode message ID. More... | |
Private Attributes | |
| std::mutex | m_mutex |
| Mutex to lock access. | |
| std::string | m_unknownLogMsgLevel {"?"} |
| String for unknown message level. | |
| std::unordered_map< eLogMessageLevel, std::string > | m_logMsgLevelLookup |
| Message level string lookup map. More... | |
| std::set< eLogMessageLevel > | m_logMsgFilterSet {} |
| Message level filter set. | |
| Formatter | m_logFormatter {} |
| Log formatter object. | |
| long | m_maxLogSize {5 * BYTES_IN_MEBIBYTE} |
| Log file max size. | |
| std::ofstream | m_ofStream {} |
| Output file stream. | |
| std::string | m_softwareVersion {} |
| Software version string. | |
| std::string | m_logFilePath {} |
| Path to current log file. | |
| std::string | m_oldLogFilePath {} |
| Path to old log file. | |
| std::unique_ptr< log_msg_queue > | m_logMsgQueueThread |
| Unique_ptr holding message queue thread. More... | |
DebugLog class.
Templated class to perform logging. The class is threaded and thread safe.
The template args comprise a formatter type and which should be a function object with same prototype as DefaultLogFormat::operator()().
The second arg is optional and controls the size at which the log will close and switch to a new file. Only 2 files ever exist the "log".txt and "log"_old.txt. The default log size is 5MiB.
|
private |
|
default |
|
inline |
Initialisation constructor.
| [in] | softwareVersion | - Version of software that "owns" the log. |
| [in] | logFolderPath | - Folder path (with trailing slash) where log will be created. |
| [in] | logName | - File name of log file without extension. |
| [in] | maxLogSize | - (Optional) The maximum size for the log file. |
Create the DebugLog in given folder with given name. A ".txt" extension is automatically appending to log file's name.
|
inline |
Add message to the log file.
| [in] | message | - Message to add to log. |
Add a simple message to the log without any extra properties set, such as file, line no. etc.
|
inline |
Add message to the log file.
| [in] | message | - Message to add to log. |
| [in] | file | - Source file in which message AddLogMessage was called, e.g. std::string(FILE). |
| [in] | function | - Function in source file in which message AddLogMessage was called, e.g. BOOST_CURRENT_FUNCTION. |
| [in] | lineNo | - Line number in the source file where AddLogMessage was called, e.g. LINE. |
| [in] | logMsgLevel | - Message level. |
Add a message to the log with extra properties set, such as file, line no. etc.
|
inline |
Add level to filter.
| [in] | logMessageLevel | - Message level to filter out of log. |
You can dynamically filter out log message from appearing in the log file based on adding message levels to the filter set. For example, you may want to filter out messages of type eLogMessageLevel::warning. In this case after calling this function with eLogMessageLevel::warning messages of this type will not appear in the log from this point until you later remove the filter.
|
inlineprivate |
Check size of current log file.
| [in] | requiredSpace | - Space required in file to write new message. |
|
inline |
Clear all message levels from filter.
Clear the filter set. AFter calling this messages of all levels will once again appear in the log file.
|
inlineprivate |
Get message level as a string.
| [in] | logMessageLevel | - Message level. |
|
inline |
Instantiate a previously default constructed DebugLog object.
| [in] | softwareVersion | - Version of software that "owns" the log. |
| [in] | logFolderPath | - Folder path (with trailing slash) where log will be created. |
| [in] | logName | - File name of log file without extension. |
| [in] | maxLogSize | - (Optional) The maximum size for the log file. |
Instantiate the DebugLog in given folder with given name. A ".txt" extension is automatically appending to log file's name. This method should only be used when constructing a DebugLog using the default constructor.
This method throws std::runtime_error exception if object already instantiated.
|
inlineprivate |
Is message level in filter set (with mutex).
| [in] | logMessageLevel | - Message level. |
|
inlineprivate |
Is message level in filter set (no mutex).
| [in] | logMessageLevel | - Message level. |
|
inlineprivate |
Is message level in map.
| [in] | logMessageLevel | - Message level. |
|
inlinestaticprivate |
Method to decode message ID.
| [in] | message | - Message to decode. |
|
inlineprivate |
Method to process message.
| [in] | message | - Message to process. |
|
inlineprivate |
Open file stream.
| [in] | filePath | - File path. |
| [in] | fileOptions | - File options (truncate or append). |
|
inline |
Remove level from filter.
| [in] | logMessageLevel | - Message level to remove from filter set. |
If you want to make sure messages of a given level appear back in the log file after having called AddLogMsgLevelFilter at some point then call this function to remove the message level from the filter set. After calling this function messages of the specified level will once again appear in the log file.
|
inlineprivate |
Write log message to file stream.
| [in] | logMessage | - Log message, pefectly forwarded. |
|
private |
Message level string lookup map.
|
private |
Unique_ptr holding message queue thread.