Blamite Game Engine - blam!  00272.10.26.20.0001.blamite
The core library for the Blamite Game Engine.
logger.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Windows.h>
4 #include <vector>
5 
7 
8 #define DEFAULT_LOG_FILENAME "debug"
9 
10 #ifndef BLAM
11 #define BLAM
12 #endif
13 
14 //warning severities
15 #define WSV_NONE LogSeverity::None
16 #define WSV_INFO LogSeverity::Info
17 #define WSV_ERROR LogSeverity::Error
18 #define WSV_WARNING LogSeverity::Warning
19 #define WSV_SEVERE LogSeverity::Severe
20 #define WSV_CRITICAL LogSeverity::Critical
21 #define WSV_AIERR LogSeverity::AiError
22 
23 //visibility options
24 #define WVIS_NONE LogVisibility::Vis_None
25 #define WVIS_ALL LogVisibility::All
26 #define WVIS_STDOUT_ONLY LogVisibility::StdoutOnly
27 #define WVIS_FILE_ONLY LogVisibility::FileOnly
28 #define WVIS_HTML_ONLY LogVisibility::HTMLOnly
29 #define WVIS_TXT_ONLY LogVisibility::TXTOnly
30 
31 #define MAX_ERRORS_BEFORE_SUPRESSION 5
32 
33 //helpful macros
34 #define BL_LOGEVT(m) Blam::Logger::LogEvent(m);
35 #define BL_LOGEVT_ST(m, st) Blam::Logger::LogEvent(m, st);
36 #define BL_LOGEVT_SEV(m, st, sev) Blam::Logger::LogEvent(m, st, sev);
37 #define BL_LOGEVT_RGB(m, st, sev, r, g, b) Blam::Logger::LogEvent(m, st, sev, r, g, b);
38 
39 
43 {
44  None,
45  Info,
51 };
52 
57 {
59  All,
64 };
65 
70 {
75 };
76 
77 namespace Blam
78 {
82  namespace Logger
83  {
87  struct LogMessage
88  {
90 
91  std::string timestamp;
92  std::string message;
94  bool show_timestamp = true;
95 
96  bool override_color = false;
98 
100 
102  };
103 
115  class Report
116  {
117  private:
118  bool log_ready = false;
119  std::string timestamped_log_path;
120 
129  HRESULT WriteLineToText(std::string file_path, Blam::Logger::LogMessage message);
130 
139  HRESULT WriteLineToHTML(std::string file_path, Blam::Logger::LogMessage message);
140 
141  public:
142  std::string report_filename;
144 
151  Report(ReportType type, std::string filename)
152  {
153  report_filename = filename;
154  report_type = type;
155  }
156 
162  void Initialize();
163 
171  HRESULT WriteLineToFile(Blam::Logger::LogMessage message);
172 
178  int LogEvent(Blam::Logger::LogMessage message);
179 
183  void PrintStartupHeader();
184 
190  bool IsReady();
191 
195  void MarkAsReady();
196  };
197 
201  namespace Internal
202  {
211  BLAM void PrepareTextLog(std::string report_filename);
212 
221  BLAM void PrepareHTMLLog(std::string report_filename);
222 
230  BLAM std::string PrepareHTMLTemplate(std::string log_title);
231 
242 
246  BLAM void LoadConsoleColors();
247  }
248 
255  namespace Queue
256  {
261  BLAM void Flush();
262 
269 
275  BLAM std::vector<Blam::Logger::LogMessage>* GetQueue();
276  }
277 
281  BLAM void SetLoggerReady();
282 
291 
300  BLAM std::string GetSeverityCSSClass(LogSeverity severity);
301 
306  BLAM void PrepareLogger();
307 
313  BLAM void LogEventAsync(std::string message);
314 
320  BLAM void LogEvent(std::string message);
321 
328  BLAM void LogEvent(std::string message, bool show_timestamp);
329 
336  BLAM void LogEvent(std::string message, ReportType report_type);
337 
345  BLAM void LogEvent(std::string message, bool show_timestamp, LogSeverity severity);
346 
357  BLAM void LogEvent(std::string message, bool show_timestamp, LogSeverity severity, short r, short g, short b);
358 
365  BLAM void LogEvent(std::string message, LogSeverity severity);
366 
374  BLAM void LogEvent(std::string message, LogSeverity severity, ReportType report_type);
375 
383  BLAM void LogEvent(std::string message, LogSeverity severity, LogVisibility visibility);
384 
391  BLAM void LogEvent(std::string message, BlamColor color);
392 
398  BLAM void LogEvent(Blam::Logger::LogMessage message);
399 
406  BLAM void LogEventForce(std::string message, LogSeverity severity);
407 
414  BLAM void LogEventForce(std::string message, BlamColor color);
415 
423  BLAM void LogEventForce(std::string message, LogSeverity severity, LogVisibility visibility);
424 
432  BLAM void LogEventForce(std::string message, LogSeverity severity, ReportType report_type);
433 
440  }
441 }
Blam
Namespace surrounding all major engine components.
Definition: blam_api.h:18
FileOnly
@ FileOnly
The message will only be written to the log file.
Definition: logger.h:61
Error
@ Error
Indicates an error that could cause engine instability.
Definition: logger.h:46
None
@ None
Indicates no severity, and is displayed with no formatting.
Definition: logger.h:44
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:33
Blam::Logger::Report
Class representing a report file.
Definition: logger.h:115
Blam::Logger::LogMessage::report_type
ReportType report_type
The report that the message is intended for.
Definition: logger.h:89
Severe
@ Severe
Indicates a severe error that the engine most likely cannot recover from.
Definition: logger.h:48
LogVisibility
LogVisibility
Enumerator to specify log event visibility.
Definition: logger.h:56
TXTOnly
@ TXTOnly
The message will only be written to the log file, if the file is in plain text format.
Definition: logger.h:63
Blam::Logger::PrepareLogger
BLAM void PrepareLogger()
Prepares the logger for use.
Definition: logger.cpp:16
Blam::Logger::Report::LogEvent
int LogEvent(Blam::Logger::LogMessage message)
Writes a message to the log file, console, and/or STDOUT depending on the message.
Definition: report.cpp:98
Blam::Logger::LogMessage::severity
LogSeverity severity
The message severity. Defaults to None.
Definition: logger.h:93
Blam::Logger::LogMessage
Structure to store log message data.
Definition: logger.h:87
AiError
@ AiError
Placeholder for the future, indicates an error with AI.
Definition: logger.h:50
Blam::Logger::Report::report_filename
std::string report_filename
Definition: logger.h:142
Blam::Logger::Queue::GetQueue
BLAM std::vector< Blam::Logger::LogMessage > * GetQueue()
Retrieves the current message queue.
Definition: queue.cpp:169
Blam::Logger::Internal::PrepareTextLog
BLAM void PrepareTextLog(std::string report_filename)
Prepares the plain text log file for writing.
Definition: logger.cpp:115
Blam::Logger::LogMessage::visibility
LogVisibility visibility
The visibility of the log message.
Definition: logger.h:99
Blam::Logger::Report::WriteLineToFile
HRESULT WriteLineToFile(Blam::Logger::LogMessage message)
Writes a line to the report's log file(s).
Definition: file_logging.cpp:11
Blam::Logger::Report::Report
Report(ReportType type, std::string filename)
Initializes a new Report.
Definition: logger.h:151
Blam::Logger::Report::report_type
ReportType report_type
Definition: logger.h:143
Blam::Logger::LogMessage::show_timestamp
bool show_timestamp
Whether or not to show the timestamp of the message in the log file.
Definition: logger.h:94
Blam::Logger::Report::MarkAsReady
void MarkAsReady()
Marks the report as ready for use.
Definition: report.cpp:229
DebugFull
@ DebugFull
Similar to debug, but includes additional messages that would be hidden from debug.
Definition: logger.h:72
Critical
@ Critical
Indicates a critical error that the engine cannot recover from.
Definition: logger.h:49
UIDebug
@ UIDebug
Report file for all UI messages.
Definition: logger.h:74
Blam::Logger::Internal::LoadConsoleColors
BLAM void LoadConsoleColors()
Loads console color configuration.
Definition: logger.cpp:221
All
@ All
The message will be shown in all places where log output can be written.
Definition: logger.h:59
globals.h
ReportType
ReportType
Enumerator containing possible report types.
Definition: logger.h:69
Blam::Logger::LogMessage::color
BlamColor color
The overridden color information. Overrules any severity-based coloring.
Definition: logger.h:97
Internal
Definition: socket.cpp:16
WSV_NONE
#define WSV_NONE
Macro for 'None' log seveirty. Original pre-enum value was 0.
Definition: logger.h:15
Blam::Logger::LogMessage::override_color
bool override_color
Whether or not to override the message color.
Definition: logger.h:96
Blam::Logger::Queue::Flush
BLAM void Flush()
Flushes the queue, causing all messages to be written to all places they are configured to do so.
Definition: queue.cpp:17
Blam::Logger::Queue::AddMessage
BLAM void AddMessage(Blam::Logger::LogMessage message)
Adds a message to the queue.
Definition: queue.cpp:46
Warning
@ Warning
Indicates a warning message. Not something critical, but something that could cause unexpected behavi...
Definition: logger.h:47
BLAM
#define BLAM
Definition: logger.h:11
Blam::Logger::SetLoggerReady
BLAM void SetLoggerReady()
Marks all reports as ready for use.
Definition: logger.cpp:213
Vis_None
@ Vis_None
The message will not be visible anywhere.
Definition: logger.h:58
StdoutOnly
@ StdoutOnly
The message will only be shown to the in-game console and STDOUT.
Definition: logger.h:60
TagDebug
@ TagDebug
Report file for all tag related messages.
Definition: logger.h:73
Blam::Logger::Report::Initialize
void Initialize()
Initializes the report to ensure it is ready for use.
Definition: report.cpp:14
Blam::Logger::LogEventForce
BLAM void LogEventForce(std::string message, LogSeverity severity)
Forcibly logs a message to the log and/or console.
Definition: aliases.cpp:150
WVIS_ALL
#define WVIS_ALL
Macro for 'All' log visibility. Original pre-enum value was 0.
Definition: logger.h:25
Blam::Logger::Report::IsReady
bool IsReady()
Whether or not the report is ready for use.
Definition: report.cpp:224
Blam::Logger::Internal::CreateReportViewerPage
BLAM void CreateReportViewerPage()
Prepares the HTML file for the Report Viewer.
Definition: logger.cpp:136
Blam::Logger::Internal::PrepareHTMLLog
BLAM void PrepareHTMLLog(std::string report_filename)
Prepares the HTML log file.
Definition: logger.cpp:52
Info
@ Info
Indicates an informative message. Mostly redundant due to the None option.
Definition: logger.h:45
Blam::Logger::GetReport
BLAM Report * GetReport(ReportType type)
Retrieves report data with the specified type.
Definition: logger.cpp:39
Blam::Logger::Internal::PrepareHTMLTemplate
BLAM std::string PrepareHTMLTemplate(std::string log_title)
Prepares the contents of the default HTML log template.
Definition: logger.cpp:83
Blam::Logger::LogMessage::timestamp
std::string timestamp
The timestamp of the log message.
Definition: logger.h:91
Blam::Logger::LogEventAsync
BLAM void LogEventAsync(std::string message)
Logs a message to the log and/or console asynchronously.
Definition: aliases.cpp:8
Blam::Logger::Report::PrintStartupHeader
void PrintStartupHeader()
Prints the startup header to the log.
Definition: report.cpp:153
Blam::Logger::LogMessage::message
std::string message
The message contents.
Definition: logger.h:92
BlamColor
Structure representing a color.
Definition: globals.h:20
LogSeverity
LogSeverity
Enumerator to specify log event severity.
Definition: logger.h:42
Debug
@ Debug
Default report file. Contains all log messages found in other reports, excluding debug_full.
Definition: logger.h:71
Blam::Logger::LogMessage::override_duplicate_limit
bool override_duplicate_limit
Whether or not this message should ignore the duplicate message limit.
Definition: logger.h:101
HTMLOnly
@ HTMLOnly
The message will only be written to the log file, if the file is in HTML format.
Definition: logger.h:62
Blam::Logger::GetSeverityCSSClass
BLAM std::string GetSeverityCSSClass(LogSeverity severity)
Gets the CSS class name for the specified severity.
Definition: logger.cpp:190