]>
jfr.im git - solanum.git/blob - src/s_log.c
2 * ircd-ratbox: 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
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * 1.Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2.Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3.The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 * $Id: s_log.c 3209 2007-02-11 16:54:43Z jilles $
35 #include "ircd_defs.h"
38 #include "sprintf_irc.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_gline
;
51 static FILE *log_kline
;
52 static FILE *log_operspy
;
53 static FILE *log_ioerror
;
61 static struct log_struct log_table
[LAST_LOGFILE
] =
64 { &ConfigFileEntry
.fname_userlog
, &log_user
},
65 { &ConfigFileEntry
.fname_fuserlog
, &log_fuser
},
66 { &ConfigFileEntry
.fname_operlog
, &log_oper
},
67 { &ConfigFileEntry
.fname_foperlog
, &log_foper
},
68 { &ConfigFileEntry
.fname_serverlog
, &log_server
},
69 { &ConfigFileEntry
.fname_killlog
, &log_kill
},
70 { &ConfigFileEntry
.fname_klinelog
, &log_kline
},
71 { &ConfigFileEntry
.fname_glinelog
, &log_gline
},
72 { &ConfigFileEntry
.fname_operspylog
, &log_operspy
},
73 { &ConfigFileEntry
.fname_ioerrorlog
, &log_ioerror
}
77 init_main_logfile(void)
80 log_main
= fopen(logFileName
, "a");
91 log_main
= fopen(logFileName
, "a");
93 /* log_main is handled above, so just do the rest */
94 for(i
= 1; i
< LAST_LOGFILE
; i
++)
96 /* close open logfiles */
97 if(*log_table
[i
].logfile
!= NULL
)
99 fclose(*log_table
[i
].logfile
);
100 *log_table
[i
].logfile
= NULL
;
103 /* reopen those with paths */
104 if(!EmptyString(*log_table
[i
].name
))
105 *log_table
[i
].logfile
= fopen(*log_table
[i
].name
, "a");
110 ilog(ilogfile dest
, const char *format
, ...)
112 FILE *logfile
= *log_table
[dest
].logfile
;
120 va_start(args
, format
);
121 ircvsnprintf(buf
, sizeof(buf
), format
, args
);
124 ircsnprintf(buf2
, sizeof(buf2
), "%s %s\n", smalldate(), buf
);
126 if(fputs(buf2
, logfile
) < 0)
129 *log_table
[dest
].logfile
= NULL
;
136 _iprint(const char *domain
, char *buf
)
138 if (domain
== NULL
|| buf
== NULL
)
141 fprintf(stderr
, "%8s: %s\n", domain
, buf
);
145 inotice(const char *format
, ...)
150 va_start(args
, format
);
151 ircvsnprintf(buf
, sizeof(buf
), format
, args
);
154 _iprint("notice", buf
);
156 ilog(L_MAIN
, "%s", buf
);
160 iwarn(const char *format
, ...)
165 va_start(args
, format
);
166 ircvsnprintf(buf
, sizeof(buf
), format
, args
);
169 _iprint("warning", buf
);
171 ilog(L_MAIN
, "%s", buf
);
175 ierror(const char *format
, ...)
180 va_start(args
, format
);
181 ircvsnprintf(buf
, sizeof(buf
), format
, args
);
184 _iprint("error", buf
);
186 ilog(L_MAIN
, "%s", buf
);
190 report_operspy(struct Client
*source_p
, const char *token
, const char *arg
)
192 /* if its not my client its already propagated */
193 if(MyClient(source_p
))
194 sendto_match_servs(source_p
, "*", CAP_ENCAP
, NOCAPS
,
195 "ENCAP * OPERSPY %s %s",
196 token
, arg
? arg
: "");
198 sendto_realops_snomask(SNO_OPERSPY
,
199 ConfigFileEntry
.operspy_admin_only
? L_ADMIN
: L_ALL
,
201 get_oper_name(source_p
), token
,
204 ilog(L_OPERSPY
, "OPERSPY %s %s %s",
205 get_oper_name(source_p
), token
, arg
? arg
: "");
211 static char buf
[MAX_DATE_STRING
];
213 time_t ltime
= CurrentTime
;
215 lt
= localtime(<ime
);
217 ircsnprintf(buf
, sizeof(buf
), "%d/%d/%d %02d.%02d",
218 lt
->tm_year
+ 1900, lt
->tm_mon
+ 1,
219 lt
->tm_mday
, lt
->tm_hour
, lt
->tm_min
);
225 * report_error - report an error from an errno.
226 * Record error to log and also send a copy to all *LOCAL* opers online.
228 * text is a *format* string for outputing error. It must
229 * contain only two '%s', the first will be replaced
230 * by the sockhost from the client_p, and the latter will
231 * be taken from sys_errlist[errno].
233 * client_p if not NULL, is the *LOCAL* client associated with
236 * Cannot use perror() within daemon. stderr is closed in
237 * ircd and cannot be used. And, worse yet, it might have
238 * been reassigned to a normal connection...
240 * Actually stderr is still there IFF ircd was run with -s --Rodder
244 report_error(const char *text
, const char *who
, const char *wholog
, int error
)
246 who
= (who
) ? who
: "";
247 wholog
= (wholog
) ? wholog
: "";
249 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, text
, who
, strerror(error
));
251 ilog(L_IOERROR
, text
, wholog
, strerror(error
));