-
Notifications
You must be signed in to change notification settings - Fork 8
/
log.c
109 lines (96 loc) · 2.27 KB
/
log.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
/*
Eagles Bulletin Board System
Copyright (C) 1995, Ray Rocker, rocker@datasync.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "server.h"
#include <time.h>
#include <unistd.h>
#if WANTS_VARARGS_H
# include <varargs.h>
#else
# include <stdarg.h>
#endif
PATH bbs_logfile;
int bbs_loglevel;
char bbs_logsource[16];
FILE *bbs_log;
open_bbslog(logfile, loglevel)
char *logfile;
int loglevel;
{
if (logfile == NULL) return S_BADFILENAME;
strncpy(bbs_logfile, logfile, PATHLEN-1);
bbs_log = fopen(bbs_logfile, "a");
if (bbs_log == NULL) {
return S_SYSERR;
}
bbs_loglevel = loglevel;
return S_OK;
}
close_bbslog()
{
fclose(bbs_log);
return S_OK;
}
void
set_log_header(str)
char *str;
{
char *p = str;
int indx = 0;
memset(bbs_logsource, ' ', 15);
while (p && *p && indx < 16) {
bbs_logsource[indx++] = *p++;
}
bbs_logsource[15] = '\0';
}
void
#if WANTS_VARARGS_H
bbslog(va_alist)
va_dcl
#else
bbslog(int level, char *fmt, ...)
#endif
{
va_list args;
time_t now;
char timestr[40];
#if WANTS_VARARGS_H
int level;
char *fmt;
#endif
#if WANTS_VARARGS_H
va_start(args);
level = va_arg(args, int);
fmt = va_arg(args, char *);
#else
va_start(args, fmt);
#endif
if (level > bbs_loglevel) {
va_end(args);
return;
}
fseek(bbs_log, 0, SEEK_END);
if (fprintf(bbs_log, "%-16s ", bbs_logsource) == EOF) {
close_bbslog();
open_bbslog(bbs_logfile, bbs_loglevel);
fprintf(bbs_log, "%-16s ", bbs_logsource);
}
time(&now);
strftime(timestr, sizeof timestr, "%x %X", localtime(&now));
fprintf(bbs_log, "%s ", timestr);
vfprintf(bbs_log, fmt, args);
fflush(bbs_log);
va_end(args);
}