1 /************************************************************************
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
33 int console_min_level
;
34 int console_max_level
;
45 {"none","error","warn","action","chat","info","debug"}
48 static void level_setter(char* v
, int *l
, int d
)
53 if (!strcmp(logdata
.levels
[i
],v
)) {
64 int log_minlevel_setter(char* v
)
66 level_setter(v
,&logdata
.min_level
,1);
69 int log_maxlevel_setter(char* v
)
71 level_setter(v
,&logdata
.max_level
,5);
74 int log_sminlevel_setter(char* v
)
76 level_setter(v
,&logdata
.system_min_level
,4);
79 int log_smaxlevel_setter(char* v
)
81 level_setter(v
,&logdata
.system_max_level
,5);
84 int log_cminlevel_setter(char* v
)
86 level_setter(v
,&logdata
.console_min_level
,4);
89 int log_cmaxlevel_setter(char* v
)
91 level_setter(v
,&logdata
.console_max_level
,5);
94 int log_file_setter(char* v
)
97 free(logdata
.logfile
);
98 logdata
.logfile
= NULL
;
103 logdata
.logfile
= path_get(NULL
,v
,0,NULL
,0);
108 /* print formatted text to game and system consoles */
109 void vlprintf(uint8_t type
, char* fmt
,...)
119 /* if it's not logged, don't process it */
123 (type
< logdata
.min_level
|| type
> logdata
.max_level
)
124 && (type
< logdata
.system_min_level
|| type
> logdata
.system_max_level
)
125 && (type
< logdata
.console_min_level
|| type
> logdata
.console_max_level
)
132 strcpy(buff
,"ERROR: ");
137 strcpy(buff
,"WARNING: ");
142 strcpy(buff
,"ACTION: ");
147 strcpy(buff
,"CHAT: ");
152 strcpy(buff
,"DEBUG: ");
160 if (vsnprintf(b
, s
, fmt
, ap
) >= s
) {
167 if (type
>= logdata
.system_min_level
&& type
<= logdata
.system_max_level
)
168 sys_console_print(buff
,1);
169 /* TODO: log to game console */
170 /*if (type >= logdata.console_min_level && type <= logdata.console_max_level)
173 if (type
< logdata
.min_level
|| type
> logdata
.max_level
)
176 if (logdata
.logfile
) {
177 /* the only time raw file calls are used, for speed */
178 FILE *f
= fopen(logdata
.logfile
,"a");