2022-12-14 20:08:52 +00:00
|
|
|
/***
|
|
|
|
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;
|
2023-12-26 21:01:29 +00:00
|
|
|
AuMutex mutex;
|
2022-12-14 20:08:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#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); \
|
|
|
|
}
|