AuroraRuntime/Source/Logging/AuFormatterContainer.hpp

60 lines
3.3 KiB
C++
Raw Normal View History

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuFormatterContainer.hpp
Date: 2022-11-14
Author: Reece
***/
#pragma once
namespace Aurora::Logging
{
struct FormatterContainer : IFormatterContainer
{
AuSPtr<IFormatter> GetFormatter() override;
void SetFormatter(const AuSPtr<IFormatter> &pFormatter) override;
AuSPtr<IFormatter> pFormatter;
AuMutex mutex;
};
}
#define ADD_FORMATTER_CONTAINER \
FormatterContainer formatter; \
AuString FormatMessageHelper(AuUInt8 level, \
const ConsoleMessage &msg, \
bool bConsoleMode, \
bool bPersistentString, \
bool bSimplified) \
{ \
if (auto pFormatter = this->formatter.GetFormatter()) \
{ \
return pFormatter->Format(level, msg); \
} \
else \
{ \
if (bConsoleMode) \
{ \
return msg.ToConsole(); \
} \
\
if (bPersistentString) \
{ \
return msg.ToPersistentString(); \
} \
\
if (bSimplified) \
{ \
return msg.ToSimplified(); \
} \
\
return msg.line; \
} \
} \
AuSPtr<IFormatter> GetFormatter() override \
{ \
return this->formatter.GetFormatter(); \
} \
void SetFormatter(const AuSPtr<IFormatter> &pFormatter) override \
{ \
this->formatter.SetFormatter(pFormatter); \
}