-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.cpp
50 lines (44 loc) · 1 KB
/
logging.cpp
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
#include "common.h"
#include "logging.h"
struct log_t: file
{
fast_mutex guard;
}* g_log = NULL;
//static file* g_log = NULL;
bool LogInit(const const_unicode_string& log_name)
{
delete g_log;
g_log = new (nonpaged) log_t();
if(!g_log){
dbg::error("Failed allocate log file object");
return false;
}
bool ok = g_log->create(log_name.get_string(), file::open_if, file::append_data);
if(!ok){
dbg::error("Failed to open log file");
delete g_log;
g_log = NULL;
}else{
LogPut(const_ansi_string("\n-- "), false);
}
return ok;
}
void LogPut(const void* p, uint32_t cb, bool timespamp)
{
if(g_log){
fast_synchronize lock(g_log->guard);
if(timespamp){
char tbuf[32];
time_fields tm;
GetTime(&tm);
uint32_t tcb = (uint32_t)_snprintf(tbuf, sizeof(tbuf), "%02d.%02d %02d:%02d:%02d ", tm.Day, tm.Month, tm.Hour, tm.Minute, tm.Second);
g_log->write(tbuf, tcb);
}
g_log->write(p, cb);
}
}
void LogCleanup()
{
delete g_log;
g_log = NULL;
}