World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
Log.cpp
См. документацию.
1 #include <stdarg.h>
2 #include <stdio.h>
3 #include <time.h>
4 
5 #include "Engine/Log.h"
6 
7 #include "Platform/Api.h"
8 
9 bool Log::Initialize() { return this->initialized = OS_OpenConsole(); }
10 
11 void Log::Info(const wchar_t *pFormat, ...) {
12  if (this->initialized) {
13  va_list args;
14  wchar_t pMsg[8192];
15 
16  va_start(args, pFormat);
17  vswprintf_s(pMsg, 8192, pFormat, args);
18  va_end(args);
19 
20  time_t t = time(NULL);
21  struct tm tm = *localtime(&t);
22  printf("[%04d/%02d/%02d %02d:%02d:%02d] %S\n", tm.tm_year + 1900,
23  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
24  pMsg);
25  }
26 }
27 
28 void Log::Warning(const wchar_t *pFormat, ...) {
29  if (this->initialized) {
30  va_list args;
31  wchar_t pMsg[8192];
32 
33  va_start(args, pFormat);
34  vswprintf_s(pMsg, 8192, pFormat, args);
35  va_end(args);
36 
37  time_t t = time(NULL);
38  struct tm tm = *localtime(&t);
39  printf("[%04d/%02d/%02d %02d:%02d:%02d] %S\n", tm.tm_year + 1900,
40  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
41  pMsg);
42  }
43 }
44 
45 //----- (004BE386) --------------------------------------------------------
46 void log_error(const char *pMessage) {
47  const char *v1; // edi@1
48  FILE *f; // eax@1
49  FILE *v3; // esi@1
50 
51  v1 = pMessage;
52  f = fopen("errorlog.txt", "a");
53  v3 = f;
54  if (f) {
55  fprintf(f, "%s\n", v1);
56  fclose(v3);
57  fflush(v3);
58  }
59 }
Log::Info
void Info(const wchar_t *pFormat,...)
Definition: Log.cpp:11
Log::Initialize
bool Initialize()
Definition: Log.cpp:9
v1
GLfloat GLfloat v1
Definition: SDL_opengl_glext.h:694
Log::Warning
void Warning(const wchar_t *pFormat,...)
Definition: Log.cpp:28
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
log_error
void log_error(const char *pMessage)
Definition: Log.cpp:46
t
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
Log::initialized
bool initialized
Definition: Log.h:12
v3
GLfloat GLfloat GLfloat GLfloat v3
Definition: SDL_opengl_glext.h:696
OS_OpenConsole
bool OS_OpenConsole()
Definition: Lin.cpp:48
Log.h
Api.h