ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/log.c
Revision: 1247
Committed: Sat Oct 1 07:54:24 2011 UTC (13 years, 10 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/s_log.c
File size: 2621 byte(s)
Log Message:
- Rewrite and cleanup half-broken logging subsystem.
  Logfile rotating is not working yet

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * s_log.c: Logger functions.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26
27 #include "s_log.h"
28 #include "fileio.h"
29 #include "irc_string.h"
30 #include "sprintf_irc.h"
31 #include "ircd.h"
32 #include "s_misc.h"
33 #include "s_conf.h"
34 #include "memory.h"
35
36 /* some older syslogs would overflow at 2024 */
37 #define LOG_BUFSIZE 2000
38
39 static struct {
40 char path[PATH_MAX + 1];
41 size_t size;
42 FBFILE *file;
43 } log_type_table[LOG_TYPE_LAST];
44
45
46 int
47 log_add_file(unsigned int type, size_t size, const char *path)
48 {
49 if (log_type_table[type].file)
50 fbclose(log_type_table[type].file);
51 else
52 log_type_table[type].file = MyMalloc(sizeof(FBFILE));
53
54 strlcpy(log_type_table[type].path, path, sizeof(log_type_table[type].path));
55
56 return (log_type_table[type].file = fbopen(path, "a")) != NULL;
57 }
58
59 void
60 log_close_all(void)
61 {
62 unsigned int type = 0;
63
64 while (++type < LOG_TYPE_LAST)
65 {
66 if (log_type_table[type].file == NULL)
67 continue;
68
69 fbclose(log_type_table[type].file);
70 MyFree(log_type_table[type].file);
71 }
72 }
73
74 static void
75 write_log(unsigned int type, const char *message)
76 {
77 char buf[LOG_BUFSIZE];
78 size_t nbytes = 0;
79
80 if (log_type_table[type].file == NULL)
81 return;
82
83 if (ConfigLoggingEntry.timestamp)
84 nbytes = snprintf(buf, sizeof(buf), "[%s] %s\n",
85 smalldate(CurrentTime), message);
86 else
87 nbytes = snprintf(buf, sizeof(buf), "%s\n", message);
88
89 fbputs(buf, log_type_table[type].file, nbytes);
90 }
91
92 void
93 ilog(unsigned int type, const char *fmt, ...)
94 {
95 char buf[LOG_BUFSIZE];
96 va_list args;
97
98 assert(fmt);
99 assert(type >= 0 && type < LOG_TYPE_LAST);
100
101 va_start(args, fmt);
102 vsnprintf(buf, sizeof(buf), fmt, args);
103 va_end(args);
104
105 if (ConfigLoggingEntry.use_logging)
106 write_log(type, buf);
107 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision