]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/log.c
- neue configure-Option "--enable-strict-rfc".
[ngircd-alex.git] / src / ngircd / log.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001 by Alexander Barton (alex@barton.de)
4  *
5  * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6  * der GNU General Public License (GPL), wie von der Free Software Foundation
7  * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8  * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10  * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS.
11  *
12  * $Id: log.c,v 1.11 2001/12/29 03:08:49 alex Exp $
13  *
14  * log.c: Logging-Funktionen
15  *
16  * $Log: log.c,v $
17  * Revision 1.11  2001/12/29 03:08:49  alex
18  * - neue configure-Option "--enable-strict-rfc".
19  *
20  * Revision 1.10  2001/12/27 01:44:49  alex
21  * - die Verwendung von syslog kann nun abgeschaltet werden.
22  *
23  * Revision 1.9  2001/12/26 03:22:16  alex
24  * - string.h wird nun includiert.
25  *
26  * Revision 1.8  2001/12/25 23:13:00  alex
27  * - Versionsstring bei Programmstart verbessert.
28  *
29  * Revision 1.7  2001/12/25 22:04:26  alex
30  * - Aenderungen an den Debug- und Logging-Funktionen.
31  *
32  * Revision 1.6  2001/12/25 19:20:39  alex
33  * - es wird nun die Facility LOG_LOCAL5 zum Loggen verwendet.
34  *
35  * Revision 1.5  2001/12/15 00:07:56  alex
36  * - Log-Level der Start- und Stop-Meldungen angehoben.
37  *
38  * Revision 1.4  2001/12/13 02:04:16  alex
39  * - boesen "Speicherschiesser" in Log() gefixt.
40  *
41  * Revision 1.3  2001/12/12 23:31:24  alex
42  * - Zum Loggen wird nun auch syslog verwendet.
43  *
44  * Revision 1.2  2001/12/12 17:19:12  alex
45  * - in Log-Meldungen wird nun auch der Level der Meldung ausgegeben.
46  *
47  * Revision 1.1.1.1  2001/12/11 21:53:04  alex
48  * - Imported sources to CVS.
49  */
50
51
52 #define MAX_LOG_MSG_LEN 256
53
54
55 #include <portab.h>
56 #include "global.h"
57
58 #include <imp.h>
59 #include <assert.h>
60 #include <stdarg.h>
61 #include <stdio.h>
62 #include <string.h>
63
64 #ifdef USE_SYSLOG
65 #include <syslog.h>
66 #endif
67
68 #include <exp.h>
69 #include "log.h"
70
71
72 GLOBAL VOID Log_Init( VOID )
73 {
74         CHAR txt[64];
75
76         strcpy( txt, "" );
77
78 #ifdef USE_SYSLOG
79         if( txt[0] ) strcat( txt, "+" );
80         else strcat( txt, "-" );
81         strcat( txt, "SYSLOG" );
82 #endif
83 #ifdef STRICT_RFC
84         if( txt[0] ) strcat( txt, "+" );
85         else strcat( txt, "-" );
86         strcat( txt, "RFC" );
87 #endif
88 #ifdef DEBUG
89         if( txt[0] ) strcat( txt, "+" );
90         else strcat( txt, "-" );
91         strcat( txt, "DEBUG" );
92 #endif
93 #ifdef SNIFFER
94         if( txt[0] ) strcat( txt, "+" );
95         else strcat( txt, "-" );
96         strcat( txt, "SNIFFER" );
97 #endif
98
99 #ifdef USE_SYSLOG
100         openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
101 #endif
102         Log( LOG_NOTICE, PACKAGE" version "VERSION"%s started.", txt );
103 } /* Log_Init */
104
105
106 GLOBAL VOID Log_Exit( VOID )
107 {
108         Log( LOG_NOTICE, PACKAGE" done.");
109 #ifdef USE_SYSLOG
110         closelog( );
111 #endif
112 } /* Log_Exit */
113
114
115 GLOBAL VOID Log( CONST INT Level, CONST CHAR *Format, ... )
116 {
117         /* Eintrag in Logfile(s) schreiben */
118
119         CHAR msg[MAX_LOG_MSG_LEN];
120         va_list ap;
121
122 #ifndef DEBUG
123         if( Level == LOG_DEBUG ) return;
124 #endif
125
126         assert( Format != NULL );
127
128         /* String mit variablen Argumenten zusammenbauen ... */
129         va_start( ap, Format );
130         vsnprintf( msg, MAX_LOG_MSG_LEN - 1, Format, ap );
131         msg[MAX_LOG_MSG_LEN - 1] = '\0';
132
133         /* ... und ausgeben */
134         printf( "[%d] %s\n", Level, msg );
135 #ifdef USE_SYSLOG
136         syslog( Level, msg );
137 #endif
138
139         va_end( ap );
140 } /* Log */
141
142
143 /* -eof- */