ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/logger.C
(Generate patch)

Comparing ermyth/src/logger.C (file contents):
Revision 1.3 by pippijn, Sat Jul 21 13:23:22 2007 UTC vs.
Revision 1.4 by pippijn, Tue Aug 28 17:08:12 2007 UTC

1/* 1/*
2 * logger.C: Logging routines 2 * logger.C: Logging routines
3 * Rights to this code are documented in doc/pod/license.pod. 3 * Rights to this code are documented in doc/pod/license.pod.
4 * 4 *
5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) 5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 */ 6 */
7 7
8static char const rcsid[] = "$Id: logger.C,v 1.3 2007/07/21 13:23:22 pippijn Exp $"; 8static char const rcsid[] = "$Id: logger.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $";
9 9
10#include "atheme.h" 10#include "atheme.h"
11#include <account/myuser.h> 11#include <account/myuser.h>
12 12
13static logfile_t *log_file; 13static logfile_t *log_file;
14int log_force; 14int log_force;
15 15
16static list_t log_files = { NULL, NULL, 0 }; 16static list_t log_files;
17 17
18/* private destructor function for logfile_t. */ 18/* private destructor function for logfile_t. */
19static void 19static void
20logfile_delete (void *vdata) 20logfile_delete (void *vdata)
21{ 21{
22 logfile_t *lf = static_cast<logfile_t *> (vdata); 22 logfile_t *lf = static_cast<logfile_t *> (vdata);
23 23
24 logfile_unregister (lf); 24 logfile_unregister (lf);
25 25
26 fclose (static_cast<FILE *> (lf->log_file)); 26 fclose (static_cast<FILE *> (lf->log_file));
27 free (lf->log_path); 27 sfree (lf->log_path);
28 free (lf); 28 delete lf;
29} 29}
30 30
31/* 31/*
32 * logfile_write(logfile_t *lf, const char *buf) 32 * logfile_write(logfile_t *lf, char const * const buf)
33 * 33 *
34 * Writes an I/O stream to a static file. 34 * Writes an I/O stream to a static file.
35 * 35 *
36 * Inputs: 36 * Inputs:
37 * - logfile_t representing the I/O stream. 37 * - logfile_t representing the I/O stream.
42 * 42 *
43 * Side Effects: 43 * Side Effects:
44 * - none 44 * - none
45 */ 45 */
46void 46void
47logfile_write (logfile_t *lf, const char *buf) 47logfile_write (logfile_t *lf, char const * const buf)
48{ 48{
49 char datetime[64]; 49 char datetime[64];
50 time_t t; 50 time_t t;
51 struct tm tm; 51 struct tm tm;
52 52
83} 83}
84 84
85/* 85/*
86 * logfile_unregister(logfile_t *lf) 86 * logfile_unregister(logfile_t *lf)
87 * 87 *
88 * Registers a log I/O stream. 88 * Unregisters a log I/O stream.
89 * 89 *
90 * Inputs: 90 * Inputs:
91 * - logfile_t representing the I/O stream. 91 * - logfile_t representing the I/O stream.
92 * 92 *
93 * Outputs: 93 * Outputs:
94 * - none 94 * - none
95 * 95 *
96 * Side Effects: 96 * Side Effects:
97 * - log_files is populated with the given object. 97 * - the given object is removed from log_files, but remains valid.
98 */ 98 */
99void 99void
100logfile_unregister (logfile_t *lf) 100logfile_unregister (logfile_t *lf)
101{ 101{
102 node_del (&lf->node, &log_files); 102 node_del (&lf->node, &log_files);
103} 103}
104 104
105/* 105/*
106 * logfile_new(const char *log_path, unsigned int log_mask) 106 * logfile_new(char const * const log_path, unsigned int log_mask)
107 * 107 *
108 * Logfile object factory. 108 * Logfile object factory.
109 * 109 *
110 * Inputs: 110 * Inputs:
111 * - path to new logfile 111 * - path to new logfile
116 * 116 *
117 * Side Effects: 117 * Side Effects:
118 * - log_files is populated with the newly created logfile_t. 118 * - log_files is populated with the newly created logfile_t.
119 */ 119 */
120logfile_t * 120logfile_t *
121logfile_new (const char *path, unsigned int log_mask) 121logfile_new (char const * const path, unsigned int log_mask)
122{ 122{
123 static time_t lastfail = 0; 123 static time_t lastfail = 0;
124 logfile_t *lf = static_cast<logfile_t *> (scalloc (sizeof (logfile_t), 1)); 124 logfile_t *lf = new logfile_t;
125 125
126 object_init (asobject (lf), path, logfile_delete); 126 object_init (asobject (lf), path, logfile_delete);
127 if ((lf->log_file = fopen (path, "a")) == NULL) 127 if ((lf->log_file = fopen (path, "a")) == NULL)
128 { 128 {
129 free (lf); 129 delete lf;
130 130
131 if (me.connected && lastfail + 3600 < NOW) 131 if (me.connected && lastfail + 3600 < NOW)
132 { 132 {
133 lastfail = NOW; 133 lastfail = NOW;
134 wallops (_("Could not open log file (%s), log entries will be missing!"), strerror (errno)); 134 wallops (_("Could not open log file (%s), log entries will be missing!"), strerror (errno));
247 return; 247 return;
248 log_file->log_mask = mask; 248 log_file->log_mask = mask;
249} 249}
250 250
251/* 251/*
252 * slog(unsigned int level, const char *fmt, ...) 252 * slog(unsigned int level, char const * const fmt, ...)
253 * 253 *
254 * Handles the basic logging of log messages to the log files defined 254 * Handles the basic logging of log messages to the log files defined
255 * in the configuration file. All I/O is handled here, and no longer 255 * in the configuration file. All I/O is handled here, and no longer
256 * in the various sourceinfo_t log transforms. 256 * in the various sourceinfo_t log transforms.
257 * 257 *
265 * 265 *
266 * Side Effects: 266 * Side Effects:
267 * - logfiles are updated depending on how they are configured. 267 * - logfiles are updated depending on how they are configured.
268 */ 268 */
269void 269void
270slog (unsigned int level, const char *fmt, ...) 270slog (unsigned int level, char const * const fmt, ...)
271{ 271{
272 va_list args; 272 va_list args;
273 char buf[BUFSIZE]; 273 char buf[BUFSIZE];
274 node_t *n; 274 node_t *n;
275 char datetime[64]; 275 char datetime[64];
303 if (((runflags & (RF_LIVE | RF_STARTING)) && (log_file != NULL ? log_file->log_mask : LG_ERROR | LG_INFO) & level) || ((runflags & RF_LIVE) && log_force)) 303 if (((runflags & (RF_LIVE | RF_STARTING)) && (log_file != NULL ? log_file->log_mask : LG_ERROR | LG_INFO) & level) || ((runflags & RF_LIVE) && log_force))
304 fprintf (stderr, "%s %s\n", datetime, buf); 304 fprintf (stderr, "%s %s\n", datetime, buf);
305} 305}
306 306
307/* 307/*
308 * logcommand(sourceinfo_t *si, int level, const char *fmt, ...) 308 * logcommand(sourceinfo_t *si, int level, char const * const fmt, ...)
309 * 309 *
310 * Logs usage of a command from a user or other source (RPC call) as 310 * Logs usage of a command from a user or other source (RPC call) as
311 * described by sourceinfo_t. 311 * described by sourceinfo_t.
312 * 312 *
313 * Inputs: 313 * Inputs:
321 * 321 *
322 * Side Effects: 322 * Side Effects:
323 * - qualifying logfile_t objects in log_files are updated. 323 * - qualifying logfile_t objects in log_files are updated.
324 */ 324 */
325void 325void
326logcommand (sourceinfo_t *si, int level, const char *fmt, ...) 326logcommand (sourceinfo_t *si, int level, char const * const fmt, ...)
327{ 327{
328 va_list args; 328 va_list args;
329 char lbuf[BUFSIZE]; 329 char lbuf[BUFSIZE];
330 330
331 va_start (args, fmt); 331 va_start (args, fmt);
336 else 336 else
337 logcommand_external (si->service, si->v != NULL ? si->v->description : "unknown", si->connection, si->sourcedesc, si->smu, level, "%s", lbuf); 337 logcommand_external (si->service, si->v != NULL ? si->v->description : "unknown", si->connection, si->sourcedesc, si->smu, level, "%s", lbuf);
338} 338}
339 339
340/* 340/*
341 * logcommand_user(service_t *svs, user_t *source, int level, const char *fmt, ...) 341 * logcommand_user(service_t *svs, user_t *source, int level, char const * const fmt, ...)
342 * 342 *
343 * Logs usage of a command from a user as described by sourceinfo_t. 343 * Logs usage of a command from a user as described by sourceinfo_t.
344 * 344 *
345 * Inputs: 345 * Inputs:
346 * - service_t object which describes the service the command is attached to 346 * - service_t object which describes the service the command is attached to
354 * 354 *
355 * Side Effects: 355 * Side Effects:
356 * - qualifying logfile_t objects in log_files are updated. 356 * - qualifying logfile_t objects in log_files are updated.
357 */ 357 */
358void 358void
359logcommand_user (service_t *svs, user_t *source, int level, const char *fmt, ...) 359logcommand_user (service_t *svs, user_t *source, int level, char const * const fmt, ...)
360{ 360{
361 va_list args; 361 va_list args;
362 char lbuf[BUFSIZE]; 362 char lbuf[BUFSIZE];
363 363
364 va_start (args, fmt); 364 va_start (args, fmt);
367 367
368 slog (level, "%s %s:%s!%s@%s[%s] %s", svs != NULL ? svs->name : me.name, source->myuser != NULL ? source->myuser->name : "", source->nick, source->user, source->vhost, source->ip[0] != '\0' ? source->ip : source->host, lbuf); 368 slog (level, "%s %s:%s!%s@%s[%s] %s", svs != NULL ? svs->name : me.name, source->myuser != NULL ? source->myuser->name : "", source->nick, source->user, source->vhost, source->ip[0] != '\0' ? source->ip : source->host, lbuf);
369} 369}
370 370
371/* 371/*
372 * logcommand_external(service_t *svs, const char *type, connection_t *source, 372 * logcommand_external(service_t *svs, char const * const type, connection_t *source,
373 * const char *sourcedesc, myuser_t *login, int level, const char *fmt, ...) 373 * char const * const sourcedesc, myuser_t *login, int level, char const * const fmt, ...)
374 * 374 *
375 * Logs usage of a command from an RPC call as described by sourceinfo_t. 375 * Logs usage of a command from an RPC call as described by sourceinfo_t.
376 * 376 *
377 * Inputs: 377 * Inputs:
378 * - service_t object which describes the service the command is attached to 378 * - service_t object which describes the service the command is attached to
389 * 389 *
390 * Side Effects: 390 * Side Effects:
391 * - qualifying logfile_t objects in log_files are updated. 391 * - qualifying logfile_t objects in log_files are updated.
392 */ 392 */
393void 393void
394logcommand_external (service_t *svs, const char *type, connection_t *source, const char *sourcedesc, myuser_t *login, int level, const char *fmt, ...) 394logcommand_external (service_t *svs, char const * const type, connection_t *source, char const * const sourcedesc, myuser_t *login, int level, char const * const fmt, ...)
395{ 395{
396 va_list args; 396 va_list args;
397 char lbuf[BUFSIZE]; 397 char lbuf[BUFSIZE];
398 398
399 va_start (args, fmt); 399 va_start (args, fmt);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines