2019-12-26 23:01:54 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2018-09-05 01:46:04 -04:00
|
|
|
|
2019-10-09 08:21:27 -04:00
|
|
|
#include "SessionMonitorPCH.h"
|
2018-09-05 01:46:04 -04:00
|
|
|
#include "Logging.h"
|
|
|
|
|
#include "StringUtils.h"
|
|
|
|
|
#include "TimeUtils.h"
|
|
|
|
|
|
|
|
|
|
EG_DEFINE_LOG_CATEGORY(LogDefault)
|
|
|
|
|
|
|
|
|
|
const char* LogVerbosityToString(ELogVerbosity v)
|
|
|
|
|
{
|
|
|
|
|
switch (v)
|
|
|
|
|
{
|
|
|
|
|
case ELogVerbosity::None:
|
|
|
|
|
return "NNN";
|
|
|
|
|
case ELogVerbosity::Fatal:
|
|
|
|
|
return "FTL";
|
|
|
|
|
case ELogVerbosity::Error:
|
|
|
|
|
return "ERR";
|
|
|
|
|
case ELogVerbosity::Warning:
|
|
|
|
|
return "WRN";
|
|
|
|
|
case ELogVerbosity::Log:
|
|
|
|
|
return "LOG";
|
2019-10-09 08:21:27 -04:00
|
|
|
case ELogVerbosity::Verbose:
|
|
|
|
|
return "LOG";
|
|
|
|
|
case ELogVerbosity::VeryVerbose:
|
|
|
|
|
return "LOG";
|
2018-09-05 01:46:04 -04:00
|
|
|
};
|
|
|
|
|
return "Unknown";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FLogCategoryBase::FLogCategoryBase(const char* Name, ELogVerbosity Verbosity, ELogVerbosity CompileTimeVerbosity)
|
2019-10-09 08:21:27 -04:00
|
|
|
: Name(Name)
|
|
|
|
|
, Verbosity(Verbosity)
|
2018-09-05 01:46:04 -04:00
|
|
|
, CompileTimeVerbosity(CompileTimeVerbosity)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FLogCategoryBase::IsSuppressed(ELogVerbosity V) const
|
|
|
|
|
{
|
|
|
|
|
return V > this->Verbosity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FLogCategoryBase::SetVerbosity(ELogVerbosity V)
|
|
|
|
|
{
|
|
|
|
|
Verbosity = ELogVerbosity(std::min((int)CompileTimeVerbosity, (int)V));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// ILogOutput
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
ILogOutput::ILogOutput()
|
|
|
|
|
{
|
2019-10-09 08:21:27 -04:00
|
|
|
FSharedData* Data = GetSharedData();
|
2018-09-05 01:46:04 -04:00
|
|
|
auto Lk = std::unique_lock<std::mutex>(Data->Mtx);
|
|
|
|
|
Data->Outputs.push_back(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ILogOutput::~ILogOutput()
|
|
|
|
|
{
|
2019-10-09 08:21:27 -04:00
|
|
|
FSharedData* Data = GetSharedData();
|
2018-09-05 01:46:04 -04:00
|
|
|
auto Lk = std::unique_lock<std::mutex>(Data->Mtx);
|
|
|
|
|
Data->Outputs.erase(std::find(Data->Outputs.begin(), Data->Outputs.end(), this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ILogOutput::FSharedData* ILogOutput::GetSharedData()
|
|
|
|
|
{
|
|
|
|
|
// This is thread safe (aka: Magic statics in C++11)
|
|
|
|
|
static FSharedData Data;
|
|
|
|
|
return &Data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ILogOutput::LogToAll(
|
|
|
|
|
const char* File, int Line, const FLogCategoryBase* Category, ELogVerbosity Verbosity,
|
|
|
|
|
_Printf_format_string_ const char* Fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list Args;
|
|
|
|
|
va_start(Args, Fmt);
|
|
|
|
|
|
|
|
|
|
const char* Prefix = "";
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
FDateTime DateTime = PARAM_LocalTime ? Now() : UtcNow();
|
|
|
|
|
Prefix = FormatString(
|
2019-10-09 08:21:27 -04:00
|
|
|
"[%s]: %s: %-11s: ",
|
2018-09-05 01:46:04 -04:00
|
|
|
DateTime.ToString(),
|
|
|
|
|
LogVerbosityToString(Verbosity),
|
|
|
|
|
Category->Name.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* Msg = FormatStringVA(Fmt, Args);
|
|
|
|
|
constexpr int BufSize = 1024*10;
|
|
|
|
|
char Buf[BufSize];
|
|
|
|
|
SNPrintf(Buf, BufSize, "%s%s\n", Prefix, Msg);
|
|
|
|
|
|
2019-10-09 08:21:27 -04:00
|
|
|
OutputDebugStringA(Buf);
|
2018-09-05 01:46:04 -04:00
|
|
|
|
2019-10-09 08:21:27 -04:00
|
|
|
FSharedData* Data = GetSharedData();
|
2018-09-05 01:46:04 -04:00
|
|
|
auto Lk = std::unique_lock<std::mutex>(Data->Mtx);
|
|
|
|
|
for (ILogOutput* Out : Data->Outputs)
|
|
|
|
|
{
|
|
|
|
|
Out->Log(File, Line, Category, Verbosity, Buf);
|
|
|
|
|
}
|
|
|
|
|
}
|