Author: Bleep <tomh@inxpress.net>
[ircu2.10.12-pk.git] / ircd / ircd_log.c
1 /************************************************************************
2  *   IRC - Internet Relay Chat, src/ircd_log.c
3  *   Copyright (C) 1999 Thomas Helvey (BleepSoft)
4  *                     
5  *   See file AUTHORS in IRC package for additional names of
6  *   the programmers. 
7  *
8  *   This program is free software; you can redistribute it and/or modify
9  *   it under the terms of the GNU General Public License as published by
10  *   the Free Software Foundation; either version 1, or (at your option)
11  *   any later version.
12  *
13  *   This program is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with this program; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  *   $Id$
23  */
24 #include "ircd_log.h"
25 #include "client.h"
26 #include "config.h"
27 #include "ircd_string.h"
28 #include "s_debug.h"
29 #include "struct.h"
30
31 #include <assert.h>
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <syslog.h>
35 #include <unistd.h>
36
37 #define LOG_BUFSIZE 2048 
38
39 static int logLevel = L_INFO;
40
41 #ifdef USE_SYSLOG
42 static int sysLogLevel[] = {
43   LOG_CRIT,
44   LOG_ERR,
45   LOG_WARNING,
46   LOG_NOTICE,
47   LOG_INFO,
48   LOG_INFO,
49   LOG_INFO
50 };
51 #endif
52
53 void ircd_log(int priority, const char* fmt, ...)
54 {
55 #if defined(USE_SYSLOG) || defined(DEBUGMODE)
56   char    buf[LOG_BUFSIZE];
57   va_list args;
58   assert(-1 < priority);
59   assert(priority < L_LAST_LEVEL);
60   assert(0 != fmt);
61
62   if (priority > logLevel)
63     return;
64
65   va_start(args, fmt);
66   vsprintf(buf, fmt, args);
67   va_end(args);
68 #endif
69 #ifdef USE_SYSLOG
70   syslog(sysLogLevel[priority], "%s", buf);
71 #endif
72 #ifdef DEBUGMODE
73   Debug((DEBUG_INFO, "LOG: %s", buf));
74 #endif
75 }
76
77 void open_log(const char* process_name)
78 {
79 #ifdef USE_SYSLOG
80   if (EmptyString(process_name))
81     process_name = "ircd";
82   openlog(process_name, LOG_PID | LOG_NDELAY, LOG_USER);
83 #endif
84 }
85
86 void close_log(void)
87 {
88 #ifdef USE_SYSLOG
89   closelog();
90 #endif
91 }
92
93 void set_log_level(int level)
94 {
95   if (L_ERROR < level && level < L_LAST_LEVEL)
96     logLevel = level;
97 }
98
99 int get_log_level(void)
100 {
101   return(logLevel);
102 }
103
104 /*
105  * ircd_log_kill - log information about a kill
106  */
107 void ircd_log_kill(const struct Client* victim, const struct Client* killer,
108                    const char* inpath, const char* path)
109 {
110   if (MyUser(victim)) {
111     /*
112      * get more infos when your local clients are killed -- _dl
113      */
114     if (IsServer(killer))
115       ircd_log(L_TRACE,
116                "A local client %s!%s@%s KILLED from %s [%s] Path: %s!%s)",
117                victim->name, victim->user->username, victim->user->host,
118                killer->name, killer->name, inpath, path);
119     else
120       ircd_log(L_TRACE,
121                "A local client %s!%s@%s KILLED by %s [%s!%s@%s] (%s!%s)",
122                victim->name, victim->user->username, victim->user->host,
123                killer->name, killer->name, killer->user->username, killer->user->host,
124                inpath, path);
125   }
126   else
127     ircd_log(L_TRACE, "KILL From %s For %s Path %s!%s",
128              killer->name, victim->name, inpath, path);
129 }
130
131