Elaztek Developer Hub
Blamite Game Engine - blam!  00357.06.18.22.0809.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 #include <fstream>
6 #include <Strings/components/interface/logger/logger.h>
7 
9 
10 #define DEFAULT_LOG_FILENAME "debug"
11 
12 #ifndef BLAM
13 #define BLAM
14 #endif
15 
16 class BlamReport;
17 
18 // Visibility options
19 #define WVIS_NONE BlamLogVisibility::None
20 #define WVIS_ALL BlamLogVisibility::All
21 #define WVIS_STDOUT_ONLY BlamLogVisibility::StdoutOnly
22 #define WVIS_FILE_ONLY BlamLogVisibility::FileOnly
23 #define WVIS_HTML_ONLY BlamLogVisibility::HTMLOnly
24 #define WVIS_TXT_ONLY BlamLogVisibility::TXTOnly
25 
26 
30 {
31  None,
32  All,
33  StdoutOnly,
34  FileOnly,
35  HTMLOnly,
36  TXTOnly
37 };
38 
42 enum class BlamReportType
43 {
44  Debug,
45  DebugFull,
46  TagDebug,
47  UIDebug,
49 };
50 
55 {
56  HTML,
57  PlainText,
58  Both
59 };
60 
65 {
67 
68  std::string timestamp;
69  std::string message;
70  BlamLogLevel severity = WSV_NONE;
71  bool show_timestamp = true;
72 
73  bool override_color = false;
74  BlamColor color;
75 
77 
78  bool override_duplicate_limit = false;
79 };
80 
81 
88 {
89 private:
90  std::string file_title = "";
91  std::string file_path = "";
93  bool stylized_html_logs = false;
94  BlamReport* report = nullptr;
95  std::string file_contents = "";
96 
105  bool PrepareAsHTML();
106 
115  bool PrepareAsPlainText();
116 
124  bool AppendMessageToHTML(BlamLogMessage message);
125 
133  bool AppendMessageToPlainText(BlamLogMessage message);
134 
135 public:
136 
144  BlamReportFile(BlamLogFileFormat file_format, std::string base_dir, BlamReport* _report);
145 
154  BlamReportFile(BlamLogFileFormat file_format, std::string base_dir, BlamReport* _report, bool is_timestamped_file);
155 
156  ~BlamReportFile();
157 
163  bool PrepareFile();
164 
172  bool AppendMessage(BlamLogMessage message);
173 
180  void Flush();
181 };
182 
195 {
196 private:
197  bool stylized_html_logs = false;
198  bool log_ready = false;
200  std::vector<BlamReportFile*> log_files = std::vector<BlamReportFile*>();
201 
202 public:
203  std::string report_filename = "debug";
205 
212  BlamReport(BlamReportType type, std::string filename);
213 
217  void Initialize();
218 
226  bool LogEvent(BlamLogMessage message);
227 
231  void PrintStartupHeader();
232 
238  bool IsReady();
239 
243  void MarkAsReady();
244 
248  void Flush();
249 };
250 
254 namespace Blam::Logger
255 {
264  namespace Queue
265  {
272  BLAM void Initialize();
273 
277  BLAM void Shutdown();
278 
283  BLAM void Flush();
284 
290  BLAM void AddMessage(BlamLogMessage message);
291 
297  BLAM std::vector<BlamLogMessage>* GetQueue();
298 
299 
300  BLAM void FlushThread();
301 
302  BLAM void StartFlushThread();
303 
304  BLAM void StopFlushThread();
305  }
306 
315 
321  BLAM std::vector<BlamReport*> GetReports();
322 
331  BLAM std::string GetLogLevelCSSClass(BlamLogLevel log_level);
332 
342  BLAM void Initialize();
343 
347  BLAM void Shutdown();
348 
354  BLAM void LogEventAsync(std::string message);
355 
361  BLAM void LogEvent(std::string message);
362 
369  BLAM void LogEvent(std::string message, bool show_timestamp);
370 
377  BLAM void LogEvent(std::string message, BlamReportType report_type);
378 
386  BLAM void LogEvent(std::string message, bool show_timestamp, BlamLogLevel severity);
387 
398  BLAM void LogEvent(std::string message, bool show_timestamp, BlamLogLevel severity, short r, short g, short b);
399 
406  BLAM void LogEvent(std::string message, BlamLogLevel severity);
407 
415  BLAM void LogEvent(std::string message, BlamLogLevel severity, BlamReportType report_type);
416 
424  BLAM void LogEvent(std::string message, BlamLogLevel severity, BlamLogVisibility visibility);
425 
432  BLAM void LogEvent(std::string message, BlamColor color);
433 
439  BLAM void LogEvent(BlamLogMessage message);
440 
446  BLAM void LogEventForce(std::string message);
447 
454  BLAM void LogEventForce(std::string message, BlamLogLevel severity);
455 
462  BLAM void LogEventForce(std::string message, BlamColor color);
463 
471  BLAM void LogEventForce(std::string message, BlamLogLevel severity, BlamLogVisibility visibility);
472 
480  BLAM void LogEventForce(std::string message, BlamLogLevel severity, BlamReportType report_type);
481 
487  BLAM void LogEventForce(BlamLogMessage message);
488 }
BlamLogMessage::report_type
BlamReportType report_type
The report that the message is intended for.
Definition: logger.h:66
BlamLogFileFormat
BlamLogFileFormat
Enumerator containing possible log file formats.
Definition: logger.h:54
BlamReportType::UIDebug
@ UIDebug
BlamReport file for all UI messages.
BlamLogVisibility::TXTOnly
@ TXTOnly
The message will only be written to the log file, if the file is in plain text format.
BlamReportFile::BlamReportFile
BlamReportFile(BlamLogFileFormat file_format, std::string base_dir, BlamReport *_report)
Creates a new BlamReportFile.
Definition: BlamReportFile.cpp:11
BlamLogFileFormat::HTML
@ HTML
The log file will be written with an HTML format.
Blam::Logger::Queue::AddMessage
BLAM void AddMessage(BlamLogMessage message)
Adds a message to the queue.
Definition: queue.cpp:70
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:141
BlamReportType::TagDebug
@ TagDebug
BlamReport file for all tag related messages.
BlamReport
Class representing a report file.
Definition: logger.h:194
BlamLogVisibility::HTMLOnly
@ HTMLOnly
The message will only be written to the log file, if the file is in HTML format.
BlamReport::Flush
void Flush()
Flushes the contents of each report file to disk.
Definition: BlamReport.cpp:184
BlamReportType
BlamReportType
Enumerator containing possible report types.
Definition: logger.h:42
BlamCommentStyle::None
@ None
The comment will be given the default appearance.
Blam::Logger::Queue::StopFlushThread
BLAM void StopFlushThread()
Definition: queue.cpp:217
BlamLogFileFormat::PlainText
@ PlainText
The log file will be written in a plain text (.txt) format.
BlamReportFile
Class representing a report file.
Definition: logger.h:87
BlamLogFileFormat::Both
@ Both
The log file will be written as both an HTML document and a plain text document.
Blam::Logger::Queue::GetQueue
BLAM std::vector< BlamLogMessage > * GetQueue()
Retrieves the current message queue.
Definition: queue.cpp:187
BlamReport::PrintStartupHeader
void PrintStartupHeader()
Prints the startup header to the log.
Definition: BlamReport.cpp:103
BlamLogMessage::visibility
BlamLogVisibility visibility
The visibility of the log message.
Definition: logger.h:76
BlamLogMessage::color
BlamColor color
The overridden color information. Overrules any severity-based coloring.
Definition: logger.h:74
BlamLogMessage::message
std::string message
The message contents.
Definition: logger.h:69
Blam::Logger::GetLogLevelCSSClass
BLAM std::string GetLogLevelCSSClass(BlamLogLevel log_level)
Gets the CSS class name for the specified log level.
Definition: logger.cpp:177
BlamReportFile::AppendMessage
bool AppendMessage(BlamLogMessage message)
Appends a message to the log file.
Definition: BlamReportFile.cpp:264
BlamReport::MarkAsReady
void MarkAsReady()
Marks the report as ready for use.
Definition: BlamReport.cpp:179
globals.h
BlamLogMessage::override_color
bool override_color
Whether or not to override the message color.
Definition: logger.h:73
BlamReportFile::PrepareFile
bool PrepareFile()
Prepares the log file for writing.
Definition: BlamReportFile.cpp:238
BlamLogVisibility::All
@ All
The message will be shown in all places where log output can be written.
BlamLogVisibility::StdoutOnly
@ StdoutOnly
The message will only be shown to the in-game console and STDOUT.
BlamReport::report_filename
std::string report_filename
The filename of this report, without the extension.
Definition: logger.h:203
BlamReport::LogEvent
bool LogEvent(BlamLogMessage message)
Writes a message to the log file, console, and/or STDOUT depending on the message.
Definition: BlamReport.cpp:77
BlamLogVisibility
BlamLogVisibility
Enumerator to specify log event visibility.
Definition: logger.h:29
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:38
BlamReport::IsReady
bool IsReady()
Whether or not the report is ready for use.
Definition: BlamReport.cpp:174
Blam::Logger::Queue::Shutdown
BLAM void Shutdown()
Flushes the queue and may later be used to perform other shutdown tasks.
Definition: queue.cpp:32
BlamReportType::ShadersDebug
@ ShadersDebug
BlamReport file for shader messages.
BlamReport::report_type
BlamReportType report_type
The type of this report.
Definition: logger.h:204
BLAM
#define BLAM
Definition: logger.h:13
Blam::Logger::Queue::StartFlushThread
BLAM void StartFlushThread()
Definition: queue.cpp:212
Blam::Logger::GetReports
BLAM std::vector< BlamReport * > GetReports()
Retrieves the list of reports.
Definition: logger.cpp:194
BlamReportType::Debug
@ Debug
Default report file. Contains all log messages found in other reports, excluding debug_full.
WVIS_ALL
#define WVIS_ALL
Macro for 'All' log visibility. Original pre-enum value was 0.
Definition: logger.h:20
BlamLogVisibility::FileOnly
@ FileOnly
The message will only be written to the log file.
Blam::Logger::Shutdown
BLAM void Shutdown()
Shuts down the logger.
Definition: logger.cpp:151
BlamLogMessage::override_duplicate_limit
bool override_duplicate_limit
Whether or not this message should ignore the duplicate message limit.
Definition: logger.h:78
BlamReportFile::Flush
void Flush()
Flushes current report contents to disk.
Definition: BlamReportFile.cpp:281
BlamLogMessage::show_timestamp
bool show_timestamp
Whether or not to show the timestamp of the message in the log file.
Definition: logger.h:71
Blam::Logger::LogEventForce
BLAM void LogEventForce(std::string message)
Forcibly logs a message to the log and/or console.
Definition: aliases.cpp:258
BlamReport::Initialize
void Initialize()
Initializes the report to ensure it is ready for use.
Definition: BlamReport.cpp:18
BlamLogMessage
Structure to store log message data.
Definition: logger.h:64
BlamReportFile::~BlamReportFile
~BlamReportFile()
Definition: BlamReportFile.cpp:86
BlamReport::BlamReport
BlamReport(BlamReportType type, std::string filename)
Initializes a new BlamReport.
Definition: BlamReport.cpp:12
Blam::Logger::LogEventAsync
BLAM void LogEventAsync(std::string message)
Logs a message to the log and/or console asynchronously.
Definition: aliases.cpp:111
BlamReportType::DebugFull
@ DebugFull
Similar to debug, but includes additional messages that would be hidden from debug.
BlamLogMessage::timestamp
std::string timestamp
The timestamp of the log message.
Definition: logger.h:68
Blam::Logger
Namespace containing things related to the Blamite Logger.
Definition: logger.h:254
Blam::Logger::Queue::FlushThread
BLAM void FlushThread()
Definition: queue.cpp:196
Blam::Logger::Queue::Initialize
BLAM void Initialize()
Initializes the logger queue.
Definition: queue.cpp:25
Blam::Logger::Initialize
BLAM void Initialize()
Prepares the logger for use.
Definition: logger.cpp:115
BlamLogMessage::severity
BlamLogLevel severity
The message severity. Defaults to None.
Definition: logger.h:70
Blam::Logger::GetReport
BLAM BlamReport * GetReport(BlamReportType type)
Retrieves report data with the specified type.
Definition: logger.cpp:164