forked from haithun/CoD4X17a_testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_logprint.c
176 lines (135 loc) · 4.83 KB
/
common_logprint.c
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
===========================================================================
Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of CoD4X17a-Server source code.
CoD4X17a-Server source code is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
CoD4X17a-Server source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================
*/
#include "q_shared.h"
#include "qcommon.h"
#include "filesystem.h"
#include "sys_thread.h"
#include <stdarg.h>
#include <time.h>
#include <string.h>
#ifndef MAXPRINTMSG
#define MAXPRINTMSG 1024
#endif
static fileHandle_t logfile;
static fileHandle_t adminlogfile;
static fileHandle_t debuglogfile;
static fileHandle_t enterleavelogfile;
void QDECL SV_EnterLeaveLog( const char *fmt, ... ) {
Sys_EnterCriticalSection(5);
va_list argptr;
char msg[MAXPRINTMSG];
char inputmsg[MAXPRINTMSG];
struct tm *newtime;
char* ltime;
time_t realtime;
// logfile
if ( com_logfile && com_logfile->integer ) {
// TTimo: only open the qconsole.log if the filesystem is in an initialized state
// also, avoid recursing in the qconsole.log opening (i.e. if fs_debug is on)
va_start (argptr,fmt);
Q_vsnprintf (inputmsg, sizeof(inputmsg), fmt, argptr);
va_end (argptr);
Com_UpdateRealtime();
realtime = Com_GetRealtime();
newtime = localtime( &realtime );
ltime = asctime( newtime );
ltime[strlen(ltime)-1] = 0;
if ( !enterleavelogfile && FS_Initialized()) {
enterleavelogfile = FS_FOpenFileAppend( "enterleave.log" );
// force it to not buffer so we get valid
if ( enterleavelogfile ){
FS_ForceFlush(enterleavelogfile);
FS_Write(va("\nLogfile opened on %s\n\n", ltime), strlen(va("\nLogfile opened on %s\n\n", ltime)), enterleavelogfile);
}
}
if ( enterleavelogfile && FS_Initialized()) {
Com_sprintf(msg, sizeof(msg), "%s: %s\n", ltime, inputmsg);
FS_Write(msg, strlen(msg), enterleavelogfile);
}
}
Sys_LeaveCriticalSection(5);
}
void QDECL Com_PrintAdministrativeLog( const char *msg ) {
Sys_EnterCriticalSection(5);
struct tm *newtime;
char* ltime;
time_t realtime;
// logfile
if ( com_logfile && com_logfile->integer ) {
// TTimo: only open the qconsole.log if the filesystem is in an initialized state
// also, avoid recursing in the qconsole.log opening (i.e. if fs_debug is on)
if ( !adminlogfile && FS_Initialized()) {
Com_UpdateRealtime();
realtime = Com_GetRealtime();
newtime = localtime( &realtime );
ltime = asctime( newtime );
ltime[strlen(ltime)-1] = 0;
adminlogfile = FS_FOpenFileAppend( "adminactions.log" );
// force it to not buffer so we get valid
if ( adminlogfile ){
FS_ForceFlush(adminlogfile);
FS_Write(va("\nLogfile opened on %s\n\n", ltime), strlen(va("\nLogfile opened on %s\n\n", ltime)), adminlogfile);
}
}
if ( adminlogfile && FS_Initialized())
{
FS_Write(msg, strlen(msg), adminlogfile);
}
}
Sys_LeaveCriticalSection(5);
}
void Com_PrintLogfile( const char *msg )
{
Sys_EnterCriticalSection(5);
if ( com_logfile && com_logfile->integer ) {
// TTimo: only open the qconsole.log if the filesystem is in an initialized state
// also, avoid recursing in the qconsole.log opening (i.e. if fs_debug is on)
if ( !logfile && FS_Initialized()) {
struct tm *newtime;
time_t aclock;
time( &aclock );
newtime = localtime( &aclock );
logfile = FS_FOpenFileWrite( "qconsole.log" );
if ( com_logfile->integer > 1 && logfile ) {
// force it to not buffer so we get valid
// data even if we are crashing
FS_ForceFlush(logfile);
}
if ( logfile ) FS_Write(va("\nLogfile opened on %s\n", asctime( newtime )), strlen(va("\nLogfile opened on %s\n", asctime( newtime ))), logfile);
}
if ( logfile && FS_Initialized())
{
FS_Write(msg, strlen(msg), logfile);
}
}
Sys_LeaveCriticalSection(5);
}
/*
This function should close all opened non Zip files
*/
void Com_CloseLogFiles()
{
if(adminlogfile)
FS_FCloseFile( adminlogfile );
if(logfile)
FS_FCloseFile( logfile );
if(debuglogfile)
FS_FCloseFile( debuglogfile );
if(enterleavelogfile)
FS_FCloseFile( enterleavelogfile );
}