Elaztek Developer Hub
Blamite Game Engine - blam!  00406.12.10.23.1457.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 
250  BLAM void FlushThread();
251 
255  BLAM void StartFlushThread();
256 
260  BLAM void StopFlushThread();
261  }
262 
270  BLAM BlamReport* GetReport(BlamReportType type);
271 
277  BLAM std::vector<BlamReport*> GetReports();
278 
287  BLAM std::string GetLogLevelCSSClass(BlamLogLevel log_level);
288 
296  BLAM BlamColor GetLogLevelColor(BlamLogLevel log_level);
297 
307  BLAM void Initialize();
308 
312  BLAM void Shutdown();
313 
319  BLAM void LogEventAsync(std::string message);
320 
326  BLAM void LogEvent(std::string message);
327 
334  BLAM void LogEvent(std::string message, bool show_timestamp);
335 
342  BLAM void LogEvent(std::string message, BlamReportType report_type);
343 
351  BLAM void LogEvent(std::string message, bool show_timestamp, BlamLogLevel severity);
352 
363  BLAM void LogEvent(std::string message, bool show_timestamp, BlamLogLevel severity, short r, short g, short b);
364 
371  BLAM void LogEvent(std::string message, BlamLogLevel severity);
372 
380  BLAM void LogEvent(std::string message, BlamLogLevel severity, BlamReportType report_type);
381 
389  BLAM void LogEvent(std::string message, BlamLogLevel severity, BlamLogVisibility visibility);
390 
397  BLAM void LogEvent(std::string message, BlamColor color);
398 
406  BLAM void LogEvent(std::string message, BlamColor color, BlamLogVisibility visibility);
407 
413  BLAM void LogEvent(BlamLogMessage message);
414 
420  BLAM void LogEventForce(std::string message);
421 
428  BLAM void LogEventForce(std::string message, BlamLogLevel severity);
429 
436  BLAM void LogEventForce(std::string message, BlamColor color);
437 
445  BLAM void LogEventForce(std::string message, BlamLogLevel severity, BlamLogVisibility visibility);
446 
454  BLAM void LogEventForce(std::string message, BlamLogLevel severity, BlamReportType report_type);
455 
461  BLAM void LogEventForce(BlamLogMessage message);
462 }
BlamVersionStringDisplayMode::Default
@ Default
Indicates the build string should use the default format.
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
apply_message_log_level_data
BlamLogMessage apply_message_log_level_data(BlamLogMessage message)
Definition: aliases.cpp:51
ENGINE_CFG_SECTION
#define ENGINE_CFG_SECTION(section_name)
Macro to quickly access a configuration section from the engine configuration file.
Definition: config.h:27
BlamUserDataFolder::Reports
@ Reports
Directory used to store the latest report (log) files. Defaults to {DataRoot}/reports/.
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:130
BLAM_VS_DATE_FRIENDLY
#define BLAM_VS_DATE_FRIENDLY
Definition: version_data.h:20
BlamException::GetType
BlamExceptionType GetType()
Retrieves the type of the exception.
Definition: BlamException.cpp:14
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
color
BlamColor color
Typedef for a color field, used in tag definitions.
Definition: tags.h:416
BlamReport::Flush
void Flush()
Flushes the contents of each report file to disk.
Definition: BlamReport.cpp:184
logger.h
use_reports
bool use_reports
Whether or not logs are being written to multiple report files.
Definition: queue.cpp:23
BlamVersionStringDisplayMode::TextLog
@ TextLog
Indicates the build string should be formatted for plain text log files.
version
date New version
Definition: chiropteraDM.txt:50
Blam::Globals::UpdateGlobal
BLAM BlamGlobalUpdateResult UpdateGlobal(std::string name, std::string new_value)
Updates the value of a String global.
Definition: globals.cpp:574
version_data.h
Blam::Placeholders::ApplyPlaceholders
BLAM std::string ApplyPlaceholders(std::string string)
Replaces any and all placeholder tags in the specified string with their evaulated values.
Definition: placeholders.cpp:21
DEFAULT_LOG_FILENAME
#define DEFAULT_LOG_FILENAME
Specifies the default filename of a log file, without the extension.
Definition: logger.h:10
BlamArithmeticErrorException::BlamArithmeticErrorException
BlamArithmeticErrorException(std::string _message)
Constructs a new arithmetic error exception.
Definition: BlamArithmeticErrorException.cpp:3
Blam::Logger::Queue::StopFlushThread
BLAM void StopFlushThread()
Stops the logger queue flush thread.
Definition: queue.cpp:217
engine_text.h
USER_DATA_PATH
#define USER_DATA_PATH(path)
Macro to quickly access a user data folder.
Definition: config.h:41
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
BlamAccessViolationException::BlamAccessViolationException
BlamAccessViolationException(std::string _message)
Constructs a new access violation exception.
Definition: BlamAccessViolationException.cpp:3
BlamLogFileFormat::Both
@ Both
The log file will be written as both an HTML document and a plain text document.
BlamUserDataFolder::LogArchives
@ LogArchives
Directory used to store previous log archives. Defaults to {DataRoot}/logs/.
Blam::Settings::Config::GetConfiguration
BLAM BlamConfigurationFile * GetConfiguration(std::string filename)
Retrieves a configuration file from a file path.
Definition: config.cpp:70
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
BlamException::BlamException
BlamException(BlamExceptionType _type, std::string _message)
Constructs a new Blamite exception.
Definition: BlamException.cpp:3
Blam::Logger::GetLogLevelCSSClass
BLAM std::string GetLogLevelCSSClass(BlamLogLevel log_level)
Gets the CSS class name for the specified log level.
Definition: logger.cpp:191
Blam::Globals::GetGlobalAsColor
BLAM BlamColor * GetGlobalAsColor(std::string name)
Retrieves a global's value as a BlamColor.
Definition: globals.cpp:415
Blam::Settings::Config::LoadConfiguration
BLAM BlamResult LoadConfiguration(std::string filename)
Loads a configuration file from a file path.
Definition: config.cpp:16
Blam::EngineDefs::GetVersionBuildString
BLAM std::string GetVersionBuildString(BlamVersionStringDisplayMode display_mode)
Retrieves the build string of the engine.
Definition: engine_definitions.cpp:53
BlamReportFile::AppendMessage
bool AppendMessage(BlamLogMessage message)
Appends a message to the log file.
Definition: BlamReportFile.cpp:264
BlamExceptionType
BlamExceptionType
Enumerator listing all possible Blamite exceptions.
Definition: exception.h:12
reports
std::vector< BlamReport * > reports
List of all reports.
Definition: logger.cpp:14
BlamReport::MarkAsReady
void MarkAsReady()
Marks the report as ready for use.
Definition: BlamReport.cpp:179
ENGINE_VERSION
#define ENGINE_VERSION
Definition: version_data.h:31
Blam::EngineText::StringExists
BLAM bool StringExists(std::string id)
Looks through the list of loaded engine strings to see if a given string has been loaded.
Definition: engine_text.cpp:69
ENGINE_CFG
#define ENGINE_CFG
Macro to allow quicker access to the main configuration file.
Definition: config.h:20
ENGINE_DATA_PATH
#define ENGINE_DATA_PATH(path)
Macro to quickly access a game engine data folder.
Definition: config.h:34
LoadConsoleColors
void LoadConsoleColors()
Loads console color configuration.
Definition: logger.cpp:19
BlamReportFile::PrepareFile
bool PrepareFile()
Prepares the log file for writing.
Definition: BlamReportFile.cpp:238
BlamException::GetExceptionMessage
std::string GetExceptionMessage()
Retrieves the message describing the exception.
Definition: BlamException.cpp:19
BLAM_VS_PROJECT_NAME
#define BLAM_VS_PROJECT_NAME
Definition: version_data.h:26
resource.h
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
BlamExceptionType::AccessViolation
@ AccessViolation
A file or memory access violation. Fired when a SIGSEGV signal is received.
globals.h
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
BlamIllegalInstructionException::BlamIllegalInstructionException
BlamIllegalInstructionException(std::string _message)
Constructs a new illegal instruction exception.
Definition: BlamIllegalInstructionException.cpp:3
BlamReport::IsReady
bool IsReady()
Whether or not the report is ready for use.
Definition: BlamReport.cpp:174
BlamEngineDataFolder::DefaultConfigs
@ DefaultConfigs
Directory containing default configuration files. Defaults to ./content/blam/default_configs/
engine_definitions.h
file
sock planetquake com All rights reserved Quake III Arena is a registered trademark of id Inc This level may be electronically distributed only at NO CHARGE to the recipient in its current MUST include this txt file
Definition: chiropteraDM.txt:95
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
BlamExceptionType::ArithmeticError
@ ArithmeticError
An arithmetic error, such as a divide by zero error. Fired when a SIGFPE signal is received.
BlamExceptionType::IllegalInstruction
@ IllegalInstruction
An illegal instruction error. Fired when a SIGILL signal is received.
Blam::Logger::Queue::StartFlushThread
BLAM void StartFlushThread()
Starts the logger queue flush thread.
Definition: queue.cpp:212
ENGINE_TEXT
#define ENGINE_TEXT(string_id)
Definition: engine_text.h:7
CONFIG_COLOR_NAME
#define CONFIG_COLOR_NAME
The filename of the default console color configuration.
Definition: config.h:15
Blam::Logger::GetReports
BLAM std::vector< BlamReport * > GetReports()
Retrieves the list of reports.
Definition: logger.cpp:208
Blam::Logger::Shutdown
BLAM void Shutdown()
Shuts down the logger.
Definition: logger.cpp:165
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:262
BlamReport::Initialize
void Initialize()
Initializes the report to ensure it is ready for use.
Definition: BlamReport.cpp:18
config.h
BlamReportFile::~BlamReportFile
~BlamReportFile()
Definition: BlamReportFile.cpp:86
placeholders.h
BlamReport::BlamReport
BlamReport(BlamReportType type, std::string filename)
Initializes a new BlamReport.
Definition: BlamReport.cpp:12
BlamUserDataFolder::DataRoot
@ DataRoot
The root of all user data. Defaults to BlamStrings::Utils::IO::GetEngineDataRoot().
Blam::Logger::LogEventAsync
BLAM void LogEventAsync(std::string message)
Logs a message to the log and/or console asynchronously.
Definition: aliases.cpp:112
CreateReportViewerPage
void CreateReportViewerPage()
Prepares the HTML file for the BlamReport Viewer.
Definition: logger.cpp:77
BlamEngineDataFolder::Gallery
@ Gallery
Directory containing general-purpose images. Defaults to ./content/Gallery/
Blam::Logger
Namespace containing things related to the Blamite Logger.
Definition: logger.h:200
BlamEngineDataFolder::Content
@ Content
Directory containing general-purpose resources. Defaults to ./content/
Blam::Logger::Queue::FlushThread
BLAM void FlushThread()
Function for the logger queue flush thread.
Definition: queue.cpp:196
BLAM_VS_TIME_FRIENDLY
#define BLAM_VS_TIME_FRIENDLY
Definition: version_data.h:21
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:129
name
ARPHIC PUBLIC LICENSE Ltd Yung Chi Taiwan All rights reserved except as specified below Everyone is permitted to copy and distribute verbatim copies of this license but changing it is forbidden Preamble The licenses for most software are designed to take away your freedom to share and change it By the ARPHIC PUBLIC LICENSE specifically permits and encourages you to use this provided that you give the recipients all the rights that we gave you and make sure they can get the modifications of this software Legal Terms Font means the TrueType fonts AR PL Mingti2L AR PL KaitiM AR PL KaitiM and the derivatives of those fonts created through any modification including modifying reordering converting changing font name
Definition: ARPHICPL.TXT:16
Blam::Logger::GetReport
BLAM BlamReport * GetReport(BlamReportType type)
Retrieves report data with the specified type.
Definition: logger.cpp:178
BlamException
Class representing a custom Blamite exception.
Definition: exception.h:26