-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleLogger.cpp
More file actions
93 lines (71 loc) · 2.75 KB
/
ConsoleLogger.cpp
File metadata and controls
93 lines (71 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2006-12 HumaNature Studios Inc.
#include "PhyreCorePch.h"
#include "HumaNature/HumaNature.h"
#include "HumaNature/OS/PlatformTimer.h"
#include "HumaNature/Debug/StackTracer.h"
#include "HumaNature/Logging/PlatformPrint.h"
DEFINE_SINGLETON_TYPE(core, ConsoleLogger);
namespace core {
ConsoleLogger::ConsoleLogger()
{
PlatformPrint::initialize();
}
ConsoleLogger::~ConsoleLogger()
{
PlatformPrint::finalize();
}
void ConsoleLogger::bindFunctions(LuaContext* context)
{
context->bind("log", this, &ConsoleLogger::SubscribeTo);
context->bind("logAll", this, &ConsoleLogger::SubscribeToAll);
context->bind("ignore", this, &ConsoleLogger::ignore);
}
Logger::ErrorBehavior Logger::logWithBreak(Severity severity, const char* category, const char* message, ...)
{
Logger::ErrorBehavior errorBehavior;
va_list vargs;
va_start(vargs, message);
errorBehavior = logVargs(severity, category, message, vargs);
va_end(vargs);
return errorBehavior;
}
Logger::ErrorBehavior ConsoleLogger::logVargs(Severity severity, const CompactStringDebug& category, const char* message, va_list& vargs)
{
if(shouldLog(severity, category))
{
LargeStaticCharBuffer buffer;
buffer.clear();
// append the header
PHYRE_SNPRINTF(buffer.getCumulativeBuffer(), buffer.getRemainingBuffer(), "%d\t%s\t%s\t", PlatformTimer::NowMilliseconds(), severityStrings[severity], category.c_str());
// append and format the message
PHYRE_VSNPRINTF(buffer.getCumulativeBuffer(), buffer.getRemainingBuffer(), message, vargs);
// append a newline
PHYRE_STRNCAT(buffer.getCumulativeBuffer(), "\n", buffer.getRemainingBuffer());
// send the message to the TTY
PlatformPrint::print(buffer.getBuffer(), severity);
return handleSeverity(severity, category, buffer, 5);
}
else
{
return kContinue;
}
}
Logger::ErrorBehavior ConsoleLogger::handleSeverity(Severity severity, const CompactStringDebug& category, LargeStaticCharBuffer& buffer, int minDepth)
{
UNUSED_PARAM(category);
UNUSED_PARAM(buffer);
if(severity <= kError)
{
StackTracer::Instance().PlatformPrintStack(severity, nullptr, minDepth);
}
if(severity <= kFatal)
{
if(!BuildPlatform::IsDebuggerPresent())
{
PlatformPrint::print("Exiting due to fatal.\n", kFatal);
BuildPlatform::Exit(1);
}
}
return severity <= kError ? kBreak : kContinue;
}
} // namespace core