]>
jfr.im git - solanum.git/blob - ircd/logger.c
2 * charybdis: an advanced Internet Relay Chat Daemon(ircd).
4 * Copyright (C) 2003 Lee H <lee@leeh.co.uk>
5 * Copyright (C) 2003-2005 ircd-ratbox development team
6 * Copyright (C) 2008 William Pitcock <nenolod@sacredspiral.co.uk>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * 1.Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * 2.Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3.The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
36 #include "ircd_defs.h"
43 static FILE *log_main
;
44 static FILE *log_user
;
45 static FILE *log_fuser
;
46 static FILE *log_oper
;
47 static FILE *log_foper
;
48 static FILE *log_server
;
49 static FILE *log_kill
;
50 static FILE *log_kline
;
51 static FILE *log_operspy
;
52 static FILE *log_ioerror
;
60 static struct log_struct log_table
[LAST_LOGFILE
] =
63 { &ConfigFileEntry
.fname_userlog
, &log_user
},
64 { &ConfigFileEntry
.fname_fuserlog
, &log_fuser
},
65 { &ConfigFileEntry
.fname_operlog
, &log_oper
},
66 { &ConfigFileEntry
.fname_foperlog
, &log_foper
},
67 { &ConfigFileEntry
.fname_serverlog
, &log_server
},
68 { &ConfigFileEntry
.fname_killlog
, &log_kill
},
69 { &ConfigFileEntry
.fname_klinelog
, &log_kline
},
70 { &ConfigFileEntry
.fname_operspylog
, &log_operspy
},
71 { &ConfigFileEntry
.fname_ioerrorlog
, &log_ioerror
}
75 verify_logfile_access(const char *filename
)
79 d
= rb_dirname(filename
);
80 dirname
= LOCAL_COPY(d
);
83 if(access(dirname
, F_OK
) == -1)
85 snprintf(buf
, sizeof(buf
), "WARNING: Unable to access logfile %s - parent directory %s does not exist", filename
, dirname
);
86 if(testing_conf
|| server_state_foreground
)
87 fprintf(stderr
, "%s\n", buf
);
88 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", buf
);
92 if(access(filename
, F_OK
) == -1)
94 if(access(dirname
, W_OK
) == -1)
96 snprintf(buf
, sizeof(buf
), "WARNING: Unable to access logfile %s - access to parent directory %s failed: %s",
97 filename
, dirname
, strerror(errno
));
98 if(testing_conf
|| server_state_foreground
)
99 fprintf(stderr
, "%s\n", buf
);
100 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", buf
);
105 if(access(filename
, W_OK
) == -1)
107 snprintf(buf
, sizeof(buf
), "WARNING: Access denied for logfile %s: %s", filename
, strerror(errno
));
108 if(testing_conf
|| server_state_foreground
)
109 fprintf(stderr
, "%s\n", buf
);
110 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", buf
);
117 init_main_logfile(void)
119 verify_logfile_access(logFileName
);
122 log_main
= fopen(logFileName
, "a");
133 log_main
= fopen(logFileName
, "a");
135 /* log_main is handled above, so just do the rest */
136 for(i
= 1; i
< LAST_LOGFILE
; i
++)
138 /* reopen those with paths */
139 if(!EmptyString(*log_table
[i
].name
))
141 verify_logfile_access(*log_table
[i
].name
);
142 *log_table
[i
].logfile
= fopen(*log_table
[i
].name
, "a");
155 /* log_main is handled above, so just do the rest */
156 for(i
= 1; i
< LAST_LOGFILE
; i
++)
158 if(*log_table
[i
].logfile
!= NULL
)
160 fclose(*log_table
[i
].logfile
);
161 *log_table
[i
].logfile
= NULL
;
167 ilog(ilogfile dest
, const char *format
, ...)
169 FILE *logfile
= *log_table
[dest
].logfile
;
177 va_start(args
, format
);
178 vsnprintf(buf
, sizeof(buf
), format
, args
);
181 snprintf(buf2
, sizeof(buf2
), "%s %s\n",
182 smalldate(rb_current_time()), buf
);
184 if(fputs(buf2
, logfile
) < 0)
187 *log_table
[dest
].logfile
= NULL
;
195 _iprint(const char *domain
, const char *buf
)
197 if (domain
== NULL
|| buf
== NULL
)
200 fprintf(stderr
, "%8s: %s\n", domain
, buf
);
204 idebug(const char *format
, ...)
210 va_start(args
, format
);
211 vsnprintf(buf
, sizeof(buf
), format
, args
);
214 _iprint("debug", buf
);
216 ilog(L_MAIN
, "%s", buf
);
221 inotice(const char *format
, ...)
226 va_start(args
, format
);
227 vsnprintf(buf
, sizeof(buf
), format
, args
);
230 _iprint("notice", buf
);
232 ilog(L_MAIN
, "%s", buf
);
236 iwarn(const char *format
, ...)
241 va_start(args
, format
);
242 vsnprintf(buf
, sizeof(buf
), format
, args
);
245 _iprint("warning", buf
);
247 ilog(L_MAIN
, "%s", buf
);
251 ierror(const char *format
, ...)
256 va_start(args
, format
);
257 vsnprintf(buf
, sizeof(buf
), format
, args
);
260 _iprint("error", buf
);
262 ilog(L_MAIN
, "%s", buf
);
266 report_operspy(struct Client
*source_p
, const char *token
, const char *arg
)
268 /* if its not my client its already propagated */
269 if(MyClient(source_p
))
270 sendto_match_servs(source_p
, "*", CAP_ENCAP
, NOCAPS
,
271 "ENCAP * OPERSPY %s %s",
272 token
, arg
? arg
: "");
274 sendto_realops_snomask(SNO_OPERSPY
,
275 ConfigFileEntry
.operspy_admin_only
? L_ADMIN
: L_ALL
,
277 get_oper_name(source_p
), token
,
280 ilog(L_OPERSPY
, "OPERSPY %s %s %s",
281 get_oper_name(source_p
), token
, arg
? arg
: "");
285 smalldate(time_t ltime
)
287 static char buf
[MAX_DATE_STRING
];
290 lt
= localtime(<ime
);
292 snprintf(buf
, sizeof(buf
), "%d/%d/%d %02d.%02d",
293 lt
->tm_year
+ 1900, lt
->tm_mon
+ 1,
294 lt
->tm_mday
, lt
->tm_hour
, lt
->tm_min
);
300 ilog_error(const char *error
)
306 errstr
= strerror(e
);
308 ilog(L_IOERROR
, "%s: %d (%s)", error
, e
, errstr
);
309 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "%s: %d (%s)",