Specifies how messages are formatted.
More...
#include <MessageFormatter.h>
|
struct | Element |
| An element to print out in the final formatted message. More...
|
|
|
enum class | ElementType {
String
, Level
, Tag
, Message
,
File
, Line
, Function
, FullFunction
,
Time
, TimeMs
, ThreadId
, ContextValue
} |
| The type of the element to print out. More...
|
|
enum class | Timezone { Local
, Utc
} |
| The timezone used to print timestamps. More...
|
|
using | LevelNameMap = std::array< std::string, levelCount > |
| Maps the log level to its name. More...
|
|
Specifies how messages are formatted.
It provides a common way to declare any message format, which can be re-used across appenders that utilize this class.
Example: if you want the message to be set to "LOG: level tag - file:line
[time] message" where the file is limited to 30 characters (cutting off on the left), the line always prints up to 5 characters, and time is set to HH:MM in UTC time:
◆ LevelNameMap
Maps the log level to its name.
Casts the log level enum value to size_t
to use as an index. Off
is not a valid name.
◆ ElementType
The type of the element to print out.
Enumerator |
---|
String | The string literal.
|
Level | The log level for the message. It is formatted as a string.
|
Tag | The tag for the log component. It is formatted as a string. This element is omitted if the tag is null or an empty string.
|
Message | The log message. It is formatted as a string.
|
File | The file that generated the message. It is formatted as a string.
|
Line | The line in the file where the message was logged. It is formatted as an unsigned integer.
|
Function | The function that generated the message. It is formatted as a string.
|
FullFunction | The fully qualified function that generated the message. It is formatted as a string.
|
Time | The timestamp of the message. It is formatted as a time using strftime() .
|
TimeMs | The millisecond portion of the timestamp. It is formatted as an unsigned integer.
|
ThreadId | The thread ID of the thread that generated the message. It is formatted as an unsigned long.
|
ContextValue | A key/value literal from LogContext; 'format' is the key to look up.
|
◆ Timezone
The timezone used to print timestamps.
Enumerator |
---|
Local | Prints time in the local time standard.
|
Utc | Prints time in the UTC standard.
|
◆ MessageFormatter() [1/2]
olp::logging::MessageFormatter::MessageFormatter |
( |
| ) |
|
|
inline |
The default constructor.
The element list is empty, the level name map is set to default, and the timezone is set to local.
◆ MessageFormatter() [2/2]
Creates the MessageFormatter
instance with the elements, level name mapping, and timezone.
- Parameters
-
elements | The elements for the formatted message. |
levelNameMap | The level name map. |
timezone | The timezone for timestamps. Defaults to local time. |
◆ createDefault()
Creates the default message formatter.
Format: "level tag - message".
◆ defaultLevelNameMap()
static const LevelNameMap& olp::logging::MessageFormatter::defaultLevelNameMap |
( |
| ) |
|
|
static |
Gets the default level name map.
- Returns
- The level name map.
◆ format()
std::string olp::logging::MessageFormatter::format |
( |
const LogMessage & |
message | ) |
const |
Formats a log message.
- Parameters
-
message | The message to format. |
- Returns
- The formatted message.
◆ getElements()
Gets the elements for the format.
- Returns
- The elements.
◆ getLevelNameMap()
Gets the level name map.
- Returns
- The level name map.
◆ getTimezone()
Gets the timezone for timestamps.
- Returns
- The timezone.
◆ setElements()
Sets the elements for the format.
- Parameters
-
◆ setLevelNameMap()
Sets the level name map.
- Parameters
-
◆ setTimezone()
Sets the timezone for timestamps.
- Parameters
-
The documentation for this class was generated from the following file: