Elaztek Developer Hub
Blamite Game Engine - blam!  00368.02.12.23.1347.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 
22 {
23  HTML,
24  PlainText,
25  Both
26 };
27 
34 {
35 private:
36  std::string file_title = "";
37  std::string file_path = "";
39  bool stylized_html_logs = false;
40  BlamReport* report = nullptr;
41  std::string file_contents = "";
42 
51  bool PrepareAsHTML();
52 
61  bool PrepareAsPlainText();
62 
70  bool AppendMessageToHTML(BlamLogMessage message);
71 
79  bool AppendMessageToPlainText(BlamLogMessage message);
80 
81 public:
82 
90  BlamReportFile(BlamLogFileFormat file_format, std::string base_dir, BlamReport* _report);
91 
100  BlamReportFile(BlamLogFileFormat file_format, std::string base_dir, BlamReport* _report, bool is_timestamped_file);
101 
102  ~BlamReportFile();
103 
109  bool PrepareFile();
110 
118  bool AppendMessage(BlamLogMessage message);
119 
126  void Flush();
127 };
128 
141 {
142 private:
143  bool stylized_html_logs = false;
144  bool log_ready = false;
146  std::vector<BlamReportFile*> log_files = std::vector<BlamReportFile*>();
147 
148 public:
149  std::string report_filename = "debug";
150  BlamReportType report_type = BlamReportType::Debug;
151 
158  BlamReport(BlamReportType type, std::string filename);
159 
163  void Initialize();
164 
172  bool LogEvent(BlamLogMessage message);
173 
177  void PrintStartupHeader();
178 
184  bool IsReady();
185 
189  void MarkAsReady();
190 
194  void Flush();
195 };
196 
200 namespace Blam::Logger
201 {
210  namespace Queue
211  {
218  BLAM void Initialize();
219 
223  BLAM void Shutdown();
224 
229  BLAM void Flush();
230 
236  BLAM void AddMessage(BlamLogMessage message);
237 
243  BLAM std::vector<BlamLogMessage>* GetQueue();
244 
245 
246  BLAM void FlushThread();
247 
248  BLAM void StartFlushThread();
249 
250  BLAM void StopFlushThread();
251  }
252 
260  BLAM BlamReport* GetReport(BlamReportType type);
261 
267  BLAM std::vector<BlamReport*> GetReports();
268 
277  BLAM std::string GetLogLevelCSSClass(BlamLogLevel log_level);
278 
286  BLAM BlamColor GetLogLevelColor(BlamLogLevel log_level);
287 
297  BLAM void Initialize();
298 
302  BLAM void Shutdown();
303 
309  BLAM void LogEventAsync(std::string message);
310 
316  BLAM void LogEvent(std::string message);
317 
324  BLAM void LogEvent(std::string message, bool show_timestamp);
325 
332  BLAM void LogEvent(std::string message, BlamReportType report_type);
333 
341  BLAM void LogEvent(std::string message, bool show_timestamp, BlamLogLevel severity);
342 
353  BLAM void LogEvent(std::string message, bool show_timestamp, BlamLogLevel severity, short r, short g, short b);
354 
361  BLAM void LogEvent(std::string message, BlamLogLevel severity);
362 
370  BLAM void LogEvent(std::string message, BlamLogLevel severity, BlamReportType report_type);
371 
379  BLAM void LogEvent(std::string message, BlamLogLevel severity, BlamLogVisibility visibility);
380 
387  BLAM void LogEvent(std::string message, BlamColor color);
388 
396  BLAM void LogEvent(std::string message, BlamColor color, BlamLogVisibility visibility);
397 
403  BLAM void LogEvent(BlamLogMessage message);
404 
410  BLAM void LogEventForce(std::string message);
411 
418  BLAM void LogEventForce(std::string message, BlamLogLevel severity);
419 
426  BLAM void LogEventForce(std::string message, BlamColor color);
427 
435  BLAM void LogEventForce(std::string message, BlamLogLevel severity, BlamLogVisibility visibility);
436 
444  BLAM void LogEventForce(std::string message, BlamLogLevel severity, BlamReportType report_type);
445 
451  BLAM void LogEventForce(BlamLogMessage message);
452 }
BlamLogFileFormat
BlamLogFileFormat
Enumerator containing possible log file formats.
Definition: logger.h:21
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:142
BlamReport
Class representing a report file.
Definition: logger.h:140
Blam::Logger::GetLogLevelColor
BLAM BlamColor GetLogLevelColor(BlamLogLevel log_level)
Retrieves the BlamColor that a specific log level should display with.
Definition: aliases.cpp:12
BlamReport::Flush
void Flush()
Flushes the contents of each report file to disk.
Definition: BlamReport.cpp:184
Blam::Logger::Queue::StopFlushThread
BLAM void StopFlushThread()
Definition: queue.cpp:217
color
BlamColor color
Typedef for a color field, used in tag definitions.
Definition: tags.h:319
BlamLogFileFormat::PlainText
@ PlainText
The log file will be written in a plain text (.txt) format.
BlamReportFile
Class representing a report file.
Definition: logger.h:33
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
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
BlamReportFile::PrepareFile
bool PrepareFile()
Prepares the log file for writing.
Definition: BlamReportFile.cpp:238
BlamReport::report_filename
std::string report_filename
The filename of this report, without the extension.
Definition: logger.h:149
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
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
BlamReport::report_type
BlamReportType report_type
The type of this report.
Definition: logger.h:150
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
Blam::Logger::Shutdown
BLAM void Shutdown()
Shuts down the logger.
Definition: logger.cpp:151
BlamReportFile::Flush
void Flush()
Flushes current report contents to disk.
Definition: BlamReportFile.cpp:281
Blam::Logger::LogEventForce
BLAM void LogEventForce(std::string message)
Forcibly logs a message to the log and/or console.
Definition: aliases.cpp:274
BlamReport::Initialize
void Initialize()
Initializes the report to ensure it is ready for use.
Definition: BlamReport.cpp:18
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:112
Blam::Logger
Namespace containing things related to the Blamite Logger.
Definition: logger.h:200
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
Blam::Logger::GetReport
BLAM BlamReport * GetReport(BlamReportType type)
Retrieves report data with the specified type.
Definition: logger.cpp:164