Skip to content

Commit

Permalink
Logger: Added additional section logging by name
Browse files Browse the repository at this point in the history
  • Loading branch information
brianferguson committed Feb 8, 2022
1 parent 85224b1 commit b8d3357
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Library/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ void Logger::WriteToLogFile(Entry& entry)
}
}

void Logger::Log(Logger::Entry* entry)
{
if (entry)
{
Log(entry->level, entry->source.c_str(), entry->message.c_str());
}
}

void Logger::Log(Level level, const WCHAR* source, const WCHAR* msg)
{
struct DelayedEntry
Expand Down Expand Up @@ -268,6 +276,22 @@ void Logger::LogSkinVF(Logger::Level level, Skin* skin, const WCHAR* format, va_
GetLogger().LogVF(level, source.c_str(), format, args);
}

void Logger::LogSkinSVF(Logger::Level level, Skin* skin, const WCHAR* section, const WCHAR* format, va_list args)
{
std::wstring source;
if (skin)
{
source = skin->GetSkinPath();
if (section)
{
source += L" - [";
source += section;
source += L']';
}
}
GetLogger().LogVF(level, source.c_str(), format, args);
}

void Logger::LogMeasureVF(Logger::Level level, Measure* measure, const WCHAR* format, va_list args)
{
if (!measure || !measure->IsDisabled())
Expand Down
11 changes: 10 additions & 1 deletion Library/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ class Logger
bool IsLogToFile() { return m_LogToFile; }
void SetLogToFile(bool logToFile);

void Log(Logger::Entry* entry);
void Log(Level level, const WCHAR* source, const WCHAR* msg);
void LogVF(Level level, const WCHAR* source, const WCHAR* format, va_list args);
void LogSkinVF(Logger::Level level, Skin* skin, const WCHAR* format, va_list args);
void LogSkinSVF(Logger::Level level, Skin* skin, const WCHAR* section, const WCHAR* format, va_list args);
void LogSection(Logger::Level level, Section* section, const WCHAR* message);
void LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args);
void LogMeasureVF(Logger::Level level, Measure* section, const WCHAR* format, va_list args);
Expand Down Expand Up @@ -97,6 +99,13 @@ inline Logger& GetLogger() { return Logger::GetInstance(); }
GetLogger().LogVF(Logger::Level::name, L"", format, args); \
va_end(args); \
} \
inline void Log ## name ## SF(Skin* skin, const WCHAR* section, const WCHAR* format, ...) \
{ \
va_list args; \
va_start(args, format); \
GetLogger().LogSkinSVF(Logger::Level::name, skin, section, format, args); \
va_end(args); \
} \
\
inline void Log ## name ## F(Section* section, const WCHAR* format, ...) \
{ \
Expand All @@ -114,7 +123,7 @@ inline Logger& GetLogger() { return Logger::GetInstance(); }
va_end(args); \
} \
\
inline void Log ## name ## F(Measure* measure, const WCHAR* format, ...)\
inline void Log ## name ## F(Measure* measure, const WCHAR* format, ...) \
{ \
va_list args; \
va_start(args, format); \
Expand Down

0 comments on commit b8d3357

Please sign in to comment.