annotate Log.cpp @ 0:9c0607679772

init
author Ritor1
date Sat, 12 Jan 2013 09:45:18 +0600
parents
children 5450af4f57ef
rev   line source
0
Ritor1
parents:
diff changeset
1 #include "Log.h"
Ritor1
parents:
diff changeset
2
Ritor1
parents:
diff changeset
3
Ritor1
parents:
diff changeset
4 #include <stdio.h>
Ritor1
parents:
diff changeset
5 #include <windows.h>
Ritor1
parents:
diff changeset
6 HANDLE hStdOut = nullptr;
Ritor1
parents:
diff changeset
7
Ritor1
parents:
diff changeset
8
Ritor1
parents:
diff changeset
9
Ritor1
parents:
diff changeset
10
Ritor1
parents:
diff changeset
11 void Log::Initialize()
Ritor1
parents:
diff changeset
12 {
Ritor1
parents:
diff changeset
13 if (AllocConsole())
Ritor1
parents:
diff changeset
14 hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
Ritor1
parents:
diff changeset
15 }
Ritor1
parents:
diff changeset
16
Ritor1
parents:
diff changeset
17
Ritor1
parents:
diff changeset
18 void Log::Warning(const wchar_t *pFormat, ...)
Ritor1
parents:
diff changeset
19 {
Ritor1
parents:
diff changeset
20 if (!hStdOut)
Ritor1
parents:
diff changeset
21 return;
Ritor1
parents:
diff changeset
22
Ritor1
parents:
diff changeset
23 va_list args;
Ritor1
parents:
diff changeset
24 wchar_t pMsg[8192];
Ritor1
parents:
diff changeset
25
Ritor1
parents:
diff changeset
26 va_start(args, pFormat);
Ritor1
parents:
diff changeset
27 vswprintf_s(pMsg, 8192, pFormat, args);
Ritor1
parents:
diff changeset
28 va_end(args);
Ritor1
parents:
diff changeset
29
Ritor1
parents:
diff changeset
30 DWORD w;
Ritor1
parents:
diff changeset
31 WriteConsole(hStdOut, pMsg, lstrlenW(pMsg), &w, nullptr);
Ritor1
parents:
diff changeset
32 WriteConsole(hStdOut, L"\r\n", 2, &w, nullptr);
Ritor1
parents:
diff changeset
33 }
Ritor1
parents:
diff changeset
34