Elaztek Developer Hub
Blamite Game Engine - blam!  00398.09.22.23.2015.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 }
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:29
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:142
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:359
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
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:22
DEFAULT_LOG_FILENAME
#define DEFAULT_LOG_FILENAME
Specifies the default filename of a log file, without the extension.
Definition: logger.h:10
Blam::Config::GetConfig
BLAM ConfigFile * GetConfig()
Retrieves the engine configuration file.
Definition: compat.cpp:5
BlamArithmeticErrorException::BlamArithmeticErrorException
BlamArithmeticErrorException(std::string _message)
Constructs a new arithmetic error exception.
Definition: BlamArithmeticErrorException.cpp:3
Blam::Logger::Queue::StopFlushThread
BLAM void StopFlushThread()
Definition: queue.cpp:217
BlamRendering::RenderStack
Namespace containing things relating to the Render Stack.
Definition: drawing.h:14
engine_text.h
USER_DATA_PATH
#define USER_DATA_PATH(path)
Macro to quickly access a user data folder.
Definition: config.h:43
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)
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
BlamRendering::RenderStack::ConsoleUI::handleNewOutput
void handleNewOutput(BlamLogMessage message)
Definition: console.hpp:346
Blam::Logger::GetLogLevelCSSClass
BLAM std::string GetLogLevelCSSClass(BlamLogLevel log_level)
Gets the CSS class name for the specified log level.
Definition: logger.cpp:192
Blam::Globals::GetGlobalAsColor
BLAM BlamColor * GetGlobalAsColor(std::string name)
Retrieves a global's value as a BlamColor.
Definition: globals.cpp:419
Blam::Settings::Config::LoadConfiguration
BLAM BlamResult LoadConfiguration(std::string filename)
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:15
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:70
ENGINE_CFG
#define ENGINE_CFG
Macro to allow quicker access to the main configuration file.
Definition: config.h:22
ENGINE_DATA_PATH
#define ENGINE_DATA_PATH(path)
Macro to quickly access a game engine data folder.
Definition: config.h:36
LoadConsoleColors
void LoadConsoleColors()
Loads console color configuration.
Definition: logger.cpp:20
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()
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:209
Blam::Logger::Shutdown
BLAM void Shutdown()
Shuts down the logger.
Definition: logger.cpp:166
BlamReportFile::Flush
void Flush()
Flushes current report contents to disk.
Definition: BlamReportFile.cpp:281
core.h
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
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:78
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()
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:130
BlamRendering::RenderStack::GetStackItem
BLAM StackObjectBase * GetStackItem(std::string id)
Retrieves an item from the render stack.
Definition: render_stack.cpp:75
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:179
Blam::Globals::UpdateGlobal
BLAM GvarUpdateResult UpdateGlobal(std::string name, std::string new_value)
Updates the value of a String global.
Definition: globals.cpp:578
BlamRendering::RenderStack::ConsoleUI
Definition: console.hpp:66
BlamException
Class representing a custom Blamite exception.
Definition: exception.h:26
console.hpp