9 #ifndef TurtleBrains_DebugLogger_hpp
10 #define TurtleBrains_DebugLogger_hpp
12 #include <turtle_brains/core/debug/tb_debug_tool_set.hpp>
13 #include <turtle_brains/core/tb_formatter.hpp>
14 #include <turtle_brains/core/tb_string.hpp>
16 #include <unordered_map>
26 #if defined(tb_enable_debug_set) || defined(tb_generate_documentation)
40 #define tb_log(formattedMessage, ...) \
41 TurtleBrains::Core::Debug::TheLogger() << TurtleBrains::Core::Debug::StartOfEntry() << \
42 TurtleBrains::Core::Formatter(formattedMessage, ##__VA_ARGS__) << TurtleBrains::Core::Debug::EndOfEntry();
59 #define tb_log_if(testResult, formattedMessage, ...) \
61 TurtleBrains::Core::Debug::TheLogger() << TurtleBrains::Core::Debug::StartOfEntry() << \
62 TurtleBrains::Core::Formatter(formattedMessage, ##__VA_ARGS__) << TurtleBrains::Core::Debug::EndOfEntry(); }
64 #define tb_debug_log(log_stream) TurtleBrains::Core::Debug::TheLogger() << TurtleBrains::Core::Debug::StartOfEntry() << log_stream << TurtleBrains::Core::Debug::EndOfEntry();
65 #define tb_debug_log_if(testResult, log_stream) if (testResult) { TurtleBrains::Core::Debug::TheLogger() << TurtleBrains::Core::Debug::StartOfEntry() << log_stream << TurtleBrains::Core::Debug::EndOfEntry(); }
66 #define tb_debug_hexdump(message, rawData, dataSize) TurtleBrains::Core::Debug::LogHexDump(message, rawData, dataSize)
68 #else //NO tb_enable_debug_set
69 #define tb_log(formattedMessage, ...) ((void)formattedMessage);
70 #define tb_log_if(test, formattedMessage, ...) ((void)(test));((void)formattedMessage);
72 #define tb_debug_log(log_stream) ;
73 #define tb_debug_log_if(testResult, log_stream) ;
74 #define tb_debug_hexdump(message, rawData, dataSize) ((void)message);((void)rawData);((void)dataSize);
78 #define tb_always_log(log_stream) TurtleBrains::Core::Debug::TheLogger() << TurtleBrains::Core::Debug::StartOfEntry() << log_stream << TurtleBrains::Core::Debug::EndOfEntry();
79 #define tb_always_log_if(testResult, log_stream) if (testResult) { TurtleBrains::Core::Debug::TheLogger() << TurtleBrains::Core::Debug::StartOfEntry() << log_stream << TurtleBrains::Core::Debug::EndOfEntry(); }
80 #define tb_always_hexdump(message, rawData, dataSize) TurtleBrains::Core::Debug::LogHexDump(message, rawData, dataSize)
138 void OpenLog(
const std::string& logFile,
bool createConsoleWindow);
161 void Log(
const char* formattedMessage, ...);
176 void LogIf(
const bool testResult,
const char* formattedMessage, ...);
181 void LogHexDump(
const char* message,
const void* rawData,
size_t dataSize);
191 LogLevel GetLogLevel(
void)
const;
192 void SetLogLevel(
const LogLevel& level);
193 void LogIfLevel(
const LogLevel& level);
199 void SaveSettings(
void);
200 void LoadSettings(
void);
216 void SetColor(
const LogColor& color);
217 void PushColor(
const LogColor& color);
220 void ClearEntry(
void);
221 void PostEntry(
void);
225 std::stringstream mLogEntry;
226 LogLevel mDebugLevel;
227 LogLevel mDefaultLevel;
232 typedef std::unordered_map<std::string, LogLevel> ChannelLevelTable;
233 ChannelLevelTable mChannelLevels;
234 std::string mCurrentChannel;
235 std::list<LogColor> mColorStack;
246 mChannelName(channelName)
252 stream.SetCurrentChannel(channel.mChannelName);
257 const std::string mChannelName;
309 const LogColor mColor;
342 explicit Setter(
const LogLevel& level) : mLogLevel(level) { }
344 friend tbCore::Debug::StreamLogger& operator<<(tbCore::Debug::StreamLogger& stream,
const Setter& setter)
346 stream.SetCurrentChannel(ChannelNamer::AsString());
347 stream.LogIfLevel(setter.mLogLevel);
380 static void LogAlways(
const char* formattedMessage, ...)
382 va_list argumentsList;
383 va_start(argumentsList, formattedMessage);
385 va_end(argumentsList);
390 static LogLevel GetLogLevel(
void)
392 return TheLogger().GetLogLevel(ChannelNamer::AsString());
395 static void SetLogLevel(
const LogLevel& logLevel)
397 TheLogger().SetLogLevel(ChannelNamer::AsString(), logLevel);
400 static inline tbCore::tbString AsString(
void) {
return ChannelNamer::AsString(); }
402 static inline Setter Always(
void) {
return Setter(LogLevel::kAlways); }
403 static inline Setter Error(
void) {
return Setter(LogLevel::kError); }
404 static inline Setter Warning(
void) {
return Setter(LogLevel::kWarning); }
405 static inline Setter Info(
void) {
return Setter(LogLevel::kInfo); }
406 static inline Setter Debug(
void) {
return Setter(LogLevel::kDebug); }
407 static inline Setter Trace(
void) {
return Setter(LogLevel::kTrace); }
411 template<
typename Type> StreamLogger& operator<<(StreamLogger& stream,
const Type& value)
413 if (stream.mDoOutput)
415 stream.mLogEntry << value;
420 inline StreamLogger& operator<<(StreamLogger& stream,
const LogColor& color)
423 if (LogColor::Reset == color)
429 stream.PushColor(color);
435 inline StreamLogger& operator<<(StreamLogger& stream,
const LogLevel& logLevel)
437 stream.LogIfLevel(logLevel);
441 inline StreamLogger& operator<<(StreamLogger& stream,
const ContinueEntry& continueEntry)
443 (void(continueEntry));
444 stream.ContinueEntry();
448 inline StreamLogger& operator<<(StreamLogger& stream,
const StartOfEntry& startOfEntry)
450 (void(startOfEntry));
455 inline StreamLogger& operator<<(StreamLogger& stream,
const EndOfEntry& endOfEntry)
462 inline StreamLogger& operator<<(StreamLogger& stream,
const Formatter& formatted)
464 if (
true == stream.mDoOutput)
466 stream.mLogEntry << formatted.c_str();
471 inline StreamLogger& operator<<(StreamLogger& stream,
const LogWithColor& coloredMessage)
473 if (
true == stream.mDoOutput)
475 stream << coloredMessage.mColor << coloredMessage.mMessage << LogColor::Reset;
480 inline StreamLogger& operator<<(StreamLogger& stream,
const LogWithQuotes& quotedMessage)
482 if (
true == stream.mDoOutput)
484 stream <<
"\"" << quotedMessage <<
"\"";
493 struct GameplayChannel {
static std::string AsString(
void) {
return (
"Gameplay"); } };
495 struct NetworkChannel {
static std::string AsString(
void) {
return (
"Network"); } };
497 struct PhysicsChannel {
static std::string AsString(
void) {
return (
"Physics"); } };
void OpenLog(const std::string &logFile, bool createConsoleWindow)
Definition: tb_debug_logger.hpp:491
Definition: tb_debug_logger.hpp:339
Definition: tb_debug_logger.hpp:493
Definition: tb_debug_logger.hpp:267
Definition: tb_debug_logger.hpp:497
void LogIf(const bool testResult, const char *formattedMessage,...)
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
Definition: tb_debug_logger.hpp:185
void LogHexDump(const char *message, const void *rawData, size_t dataSize)
Definition: tb_debug_logger.hpp:312
Definition: tb_debug_logger.hpp:273
void Log(const char *formattedMessage,...)
Definition: tb_debug_logger.hpp:336
Definition: tb_debug_logger.hpp:242
std::string tbString
Definition: tb_string.hpp:335
Definition: tb_debug_logger.hpp:495
Definition: tb_debug_logger.hpp:279
Definition: tb_debug_logger.hpp:260