NDEVR
API Documentation
LogMessage.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: LogMessage
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Time.h>
35#include <NDEVR/String.h>
36
37namespace NDEVR
38{
39 class TranslatedString;
40 class Font;
41 struct TextBlock;
42
47 class NDEVR_BASE_API LogMessage
48 {
49 public:
63 public:
75 LogMessage(const Time& time, const StringView& message, const uint01 error_level, uint02 session);
82 LogMessage(const Time& time, const StringView& message, const uint01 error_level = e_notification);
88 explicit LogMessage(const StringView& message, const uint01 error_level = e_notification);
94 explicit LogMessage(const TranslatedString& message, const uint01 error_level = e_notification);
102 StringAllocatingView message(bool include_new_lines, bool include_tabs, bool include_colors) const;
110 void appendMessage(StringAllocatingView& message, bool include_new_lines, bool include_tabs, bool include_colors) const;
115 const String& rawMessage() const { return m_message; }
131 AlocatingAlignedBuffer<TextBlock, 64> messageBlocks(const Font& default_font) const;
136 bool hasFormatting() const;
141 static constexpr StringView LogSessionStart() { return "\\--------------------------------------------------------------------------------------------------|"; }
146 static constexpr StringView LogSessionEnd() { return "/--------------------------------------------------------------------------------------------------|"; }
151 bool isSessionStart() const { return m_message == LogSessionStart(); }
156 bool isSessionEnd() const { return m_message == LogSessionStart(); }
163 bool hasSubString(const StringView& s, bool ignore_case = false) const;
168 inline Time recordTime() const {
169 return m_time;
170 }
171
175 inline void setRecordTime(const Time& time) {
176 m_time = time;
177 }
178
182 inline uint01 logRecordLevel() const {
183 return m_error_level;
184 }
185
189 inline void setErrorLevel(uint01 level) {
190 m_error_level = level;
191 }
192
196 inline void setSessionNumber(uint02 session) {
197 m_session_number = session;
198 }
199
209 public:
215 protected:
220 };
221 template class NDEVR_BASE_API StringStream<LogMessage>;
222}
223
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Information for how to display text data.
Definition Font.h:46
LogMessage(const StringView &message, const uint01 error_level=e_notification)
Constructs a LogMessage from a string view with an optional error level.
bool hasFormatting() const
Checks whether the message contains ANSI escape code formatting.
uint01 logRecordLevel() const
Returns the severity level of this log message.
Definition LogMessage.h:182
static constexpr StringView LogSessionEnd()
Returns the sentinel string that marks the end of a log session.
Definition LogMessage.h:146
uint02 m_session_number
The session number that produced this message.
Definition LogMessage.h:218
LogMessage(const Time &time, const StringView &message, const uint01 error_level=e_notification)
Constructs a LogMessage with a specific time, message, and error level.
LogMessage()
Constructs a default LogMessage with no content.
static constexpr StringView LogSessionStart()
Returns the sentinel string that marks the start of a log session.
Definition LogMessage.h:141
const String & rawMessage() const
Returns a const reference to the raw, unformatted message string.
Definition LogMessage.h:115
LogMessage(const Time &time, const StringView &message, const uint01 error_level, uint02 session)
Constructs a LogMessage with a specific time, message, error level, and session number.
bool isSessionEnd() const
Checks whether this message is a session end marker.
Definition LogMessage.h:156
void setSessionNumber(uint02 session)
Sets the session number that produced this log message.
Definition LogMessage.h:196
uint02 sessionNumber() const
Returns the session number that produced this log message.
Definition LogMessage.h:203
bool hasSubString(const StringView &s, bool ignore_case=false) const
Checks whether the message contains a given substring.
void setRecordTime(const Time &time)
Sets the timestamp of this log message.
Definition LogMessage.h:175
ApplicationMessagePriority
Defines severity levels for log messages, ranging from success to critical error.
Definition LogMessage.h:54
@ e_error
Error indicating a failure in an operation.
Definition LogMessage.h:60
@ e_success
Operation completed successfully.
Definition LogMessage.h:55
@ e_notification
Informational notification for general status updates.
Definition LogMessage.h:58
@ e_debug
Debug-level message, not persisted to the log.
Definition LogMessage.h:56
@ e_critical_error
Critical error indicating a severe or unrecoverable failure.
Definition LogMessage.h:61
@ e_warning
Warning indicating a potential issue.
Definition LogMessage.h:59
@ e_logged_debug
Debug-level message that is persisted to the log.
Definition LogMessage.h:57
uint01 m_error_level
The severity level of this log message.
Definition LogMessage.h:219
bool isSessionStart() const
Checks whether this message is a session start marker.
Definition LogMessage.h:151
Buffer< std::pair< String, String > > ansiiEscapeBlocks() const
Parses the message into pairs of ANSI escape code sequences and their associated text.
Time m_time
The timestamp when the message was recorded.
Definition LogMessage.h:217
AlocatingAlignedBuffer< TextBlock, 64 > messageBlocks(const Font &default_font) const
Converts the message into styled TextBlock objects using the specified default font.
LogMessage(const TranslatedString &message, const uint01 error_level=e_notification)
Constructs a LogMessage from a translated string with an optional error level.
Time recordTime() const
Returns the timestamp when this log message was recorded.
Definition LogMessage.h:168
static uint02 CurrentLogSession()
Returns the identifier for the current active log session.
bool isFromCurrentSession() const
Checks whether this log message was generated during the current application session.
void setErrorLevel(uint01 level)
Sets the severity level of this log message.
Definition LogMessage.h:189
void appendMessage(StringAllocatingView &message, bool include_new_lines, bool include_tabs, bool include_colors) const
Appends the formatted message to an existing string with optional formatting controls.
StringAllocatingView message(bool include_new_lines, bool include_tabs, bool include_colors) const
Returns the formatted message string with optional formatting controls.
String & rawMessage()
Returns a mutable reference to the raw, unformatted message string.
Definition LogMessage.h:120
String m_message
The raw log message content.
Definition LogMessage.h:216
This class is like a string view, but may optionally store the data internally Useful if the return t...
Definition String.h:1278
Logic for reading or writing to a string or a user friendly, TranslatedString.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
The primary namespace for the NDEVR SDK.
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
text that is formatted the same way, typically part of a bigger group of text
Definition Font.h:287