2 f4ade537 2001-12-11 alex * ngIRCd -- The Next Generation IRC Daemon
3 1547f76c 2002-01-02 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
5 f4ade537 2001-12-11 alex * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 f4ade537 2001-12-11 alex * der GNU General Public License (GPL), wie von der Free Software Foundation
7 f4ade537 2001-12-11 alex * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 f4ade537 2001-12-11 alex * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 f4ade537 2001-12-11 alex * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 804b1ec4 2001-12-31 alex * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
12 bdf53a6d 2002-03-27 alex * $Id: log.c,v 1.24 2002/03/27 16:40:06 alex Exp $
14 f4ade537 2001-12-11 alex * log.c: Logging-Funktionen
18 ca33cbda 2002-03-12 alex #include "portab.h"
20 ca33cbda 2002-03-12 alex #include "imp.h"
21 f4ade537 2001-12-11 alex #include <assert.h>
22 fe2bc90e 2002-03-06 alex #include <errno.h>
23 f4ade537 2001-12-11 alex #include <stdarg.h>
24 f4ade537 2001-12-11 alex #include <stdio.h>
25 3be92e9d 2001-12-26 alex #include <string.h>
26 fe2bc90e 2002-03-06 alex #include <sys/types.h>
27 fe2bc90e 2002-03-06 alex #include <unistd.h>
29 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
30 3d1a0962 2001-12-12 alex #include <syslog.h>
33 006c0328 2002-01-11 alex #include "ngircd.h"
34 ca33cbda 2002-03-12 alex #include "defines.h"
36 ca33cbda 2002-03-12 alex #include "exp.h"
37 f4ade537 2001-12-11 alex #include "log.h"
40 f4ade537 2001-12-11 alex GLOBAL VOID Log_Init( VOID )
42 fcb47ae6 2002-02-19 alex CHAR txt[127];
44 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
45 fcb47ae6 2002-02-19 alex /* Syslog initialisieren */
46 0dc0308d 2001-12-25 alex openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
49 fcb47ae6 2002-02-19 alex /* Hello World! */
50 006c0328 2002-01-11 alex Log( LOG_NOTICE, "%s started.", NGIRCd_Version( ));
52 fcb47ae6 2002-02-19 alex /* Informationen uebern den "Operation Mode" */
53 fcb47ae6 2002-02-19 alex strcpy( txt, "" );
54 fcb47ae6 2002-02-19 alex #ifdef DEBUG
55 fcb47ae6 2002-02-19 alex if( NGIRCd_Debug )
57 fcb47ae6 2002-02-19 alex if( txt[0] ) strcat( txt, ", " );
58 fcb47ae6 2002-02-19 alex strcat( txt, "debug-mode" );
61 fcb47ae6 2002-02-19 alex if( NGIRCd_NoDaemon )
63 fcb47ae6 2002-02-19 alex if( txt[0] ) strcat( txt, ", " );
64 fcb47ae6 2002-02-19 alex strcat( txt, "no-daemon-mode" );
66 fcb47ae6 2002-02-19 alex if( NGIRCd_Passive )
68 fcb47ae6 2002-02-19 alex if( txt[0] ) strcat( txt, ", " );
69 fcb47ae6 2002-02-19 alex strcat( txt, "passive-mode" );
71 fcb47ae6 2002-02-19 alex #ifdef SNIFFER
72 fcb47ae6 2002-02-19 alex if( NGIRCd_Sniffer )
74 fcb47ae6 2002-02-19 alex if( txt[0] ) strcat( txt, ", " );
75 fcb47ae6 2002-02-19 alex strcat( txt, "network sniffer" );
78 fcb47ae6 2002-02-19 alex if( txt[0] ) Log( LOG_INFO, "Activating: %s.", txt );
80 fe2bc90e 2002-03-06 alex /* stderr in Datei umlenken */
81 fe2bc90e 2002-03-06 alex fflush( stderr );
82 fe2bc90e 2002-03-06 alex if( ! freopen( ERROR_FILE, "a+", stderr )) Log( LOG_ERR, "Can't reopen stderr (\""ERROR_FILE"\"): %s", strerror( errno ));
84 fe2bc90e 2002-03-06 alex fprintf( stderr, "\n--- %s ---\n\n", NGIRCd_StartStr );
85 95a4b1b1 2002-03-25 alex fprintf( stderr, "%s started.\npid=%ld, ppid=%ld, uid=%ld, gid=%ld [euid=%ld, egid=%ld].\nActivating: %s\n\n", NGIRCd_Version( ), (INT32)getpid( ), (INT32)getppid( ), (INT32)getuid( ), (INT32)getgid( ), (INT32)geteuid( ), (INT32)getegid( ), txt[0] ? txt : "-" );
86 fe2bc90e 2002-03-06 alex fflush( stderr );
87 f4ade537 2001-12-11 alex } /* Log_Init */
90 f4ade537 2001-12-11 alex GLOBAL VOID Log_Exit( VOID )
94 fcb47ae6 2002-02-19 alex /* Good Bye! */
95 3b51e18c 2001-12-15 alex Log( LOG_NOTICE, PACKAGE" done.");
97 b9a2c4a8 2002-03-21 alex t = time( NULL );
98 b9a2c4a8 2002-03-21 alex fputs( ctime( &t ), stderr );
99 95a4b1b1 2002-03-25 alex fprintf( stderr, PACKAGE" done (pid=%ld).\n", (INT32)getpid( ));
100 fe2bc90e 2002-03-06 alex fflush( stderr );
102 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
103 fcb47ae6 2002-02-19 alex /* syslog abmelden */
104 3d1a0962 2001-12-12 alex closelog( );
106 f4ade537 2001-12-11 alex } /* Log_Exit */
109 f4ade537 2001-12-11 alex GLOBAL VOID Log( CONST INT Level, CONST CHAR *Format, ... )
111 f4ade537 2001-12-11 alex /* Eintrag in Logfile(s) schreiben */
113 f4ade537 2001-12-11 alex CHAR msg[MAX_LOG_MSG_LEN];
114 f4ade537 2001-12-11 alex va_list ap;
117 ec1922ef 2001-12-29 alex assert( Format != NULL );
119 006c0328 2002-01-11 alex #ifdef DEBUG
120 006c0328 2002-01-11 alex if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
122 d4a60bd4 2001-12-25 alex if( Level == LOG_DEBUG ) return;
125 f4ade537 2001-12-11 alex /* String mit variablen Argumenten zusammenbauen ... */
126 f4ade537 2001-12-11 alex va_start( ap, Format );
127 10363b39 2002-03-03 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
128 10363b39 2002-03-03 alex va_end( ap );
130 fe2bc90e 2002-03-06 alex /* In Error-File schreiben */
131 b9a2c4a8 2002-03-21 alex if( Level <= LOG_ERR )
133 b9a2c4a8 2002-03-21 alex t = time( NULL );
134 b9a2c4a8 2002-03-21 alex fputs( ctime( &t ), stderr );
135 b9a2c4a8 2002-03-21 alex fprintf( stderr, "[%d] %s\n\n", Level, msg );
138 f4ade537 2001-12-11 alex /* ... und ausgeben */
139 006c0328 2002-01-11 alex if( NGIRCd_NoDaemon ) printf( "[%d] %s\n", Level, msg );
141 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
142 fe2bc90e 2002-03-06 alex /* Syslog */
143 3d1a0962 2001-12-12 alex syslog( Level, msg );
145 f4ade537 2001-12-11 alex } /* Log */
148 ec1922ef 2001-12-29 alex GLOBAL VOID Log_Init_Resolver( VOID )
150 ec1922ef 2001-12-29 alex #ifdef USE_SYSLOG
151 ec1922ef 2001-12-29 alex openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
153 ec1922ef 2001-12-29 alex } /* Log_Init_Resolver */
156 ec1922ef 2001-12-29 alex GLOBAL VOID Log_Exit_Resolver( VOID )
158 ec1922ef 2001-12-29 alex #ifdef USE_SYSLOG
159 ec1922ef 2001-12-29 alex closelog( );
161 ec1922ef 2001-12-29 alex } /* Log_Exit_Resolver */
164 ec1922ef 2001-12-29 alex GLOBAL VOID Log_Resolver( CONST INT Level, CONST CHAR *Format, ... )
166 ec1922ef 2001-12-29 alex /* Eintrag des Resolver in Logfile(s) schreiben */
168 03783eea 2002-01-05 alex #ifndef USE_SYSLOG
172 ec1922ef 2001-12-29 alex CHAR msg[MAX_LOG_MSG_LEN];
173 ec1922ef 2001-12-29 alex va_list ap;
175 ec1922ef 2001-12-29 alex assert( Format != NULL );
177 006c0328 2002-01-11 alex #ifdef DEBUG
178 006c0328 2002-01-11 alex if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
180 ec1922ef 2001-12-29 alex if( Level == LOG_DEBUG ) return;
183 ec1922ef 2001-12-29 alex /* String mit variablen Argumenten zusammenbauen ... */
184 ec1922ef 2001-12-29 alex va_start( ap, Format );
185 10363b39 2002-03-03 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
186 10363b39 2002-03-03 alex va_end( ap );
188 ec1922ef 2001-12-29 alex /* ... und ausgeben */
189 ec1922ef 2001-12-29 alex syslog( Level, msg );
192 ec1922ef 2001-12-29 alex } /* Log_Resolver */
195 f4ade537 2001-12-11 alex /* -eof- */