summaryrefslogtreecommitdiff
path: root/src/InternalLogger.cpp
blob: de1f75000c3b7ee3820c5a562b5601d606776ce1 (plain) (blame)
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
#include "InternalLogger.h"
#include <iostream>
#include <sstream>
#include <windows.h>

std::unique_ptr<InternalLogger> g_Logger;
nv::ILogger* g_UserLogger = nullptr;

InternalLogger::InternalLogger()
{

}

InternalLogger::InternalLogger(nv::LogSeverity loggingLevel):
	LoggingLevel(loggingLevel)
{

}

nv::LogSeverity InternalLogger::getLoggingLevel()
{
	return LoggingLevel;
}

void InternalLogger::setLoggingLevel(nv::LogSeverity newLevel)
{
	LoggingLevel = newLevel;
}

void InternalLogger::log(nv::LogSeverity severity, const wchar_t* filename, int linenumber, const wchar_t* format, ...)
{
	if (getLoggingLevel() > severity)
		return;

	wchar_t buffer[1024];

	va_list args;
	va_start(args, format);
#if NV_GCC_FAMILY
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
	_vsnwprintf_s(buffer, sizeof(buffer), format, args);
#if NV_GCC_FAMILY
#pragma GCC diagnostic pop
#endif
	va_end(args);

	std::wstringstream out;

	out << filename << "(" << linenumber << "): " << "[" << nv::LogSeverityStrings[(int)severity] << "] " << buffer << std::endl;

	OutputDebugStringW(out.str().c_str());
}