2 logger.c -- logging code
3 Copyright (C) 2003 Guus Sliepen <guus@sliepen.eu.org>
4 2003 Ivo Timmermans <ivo@o2w.nl>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Id: logger.c,v 1.2 2003/08/24 20:38:24 guus Exp $
28 debug_t debug_level = DEBUG_NOTHING;
29 static logmode_t logmode = LOGMODE_STDERR;
31 extern char *logfilename;
32 static FILE *logfile = NULL;
34 static HANDLE loghandle = NULL;
36 static const char *logident = NULL;
38 void openlogger(const char *ident, logmode_t mode) {
48 logfile = fopen(logfilename, "a");
50 logmode = LOGMODE_NULL;
54 loghandle = RegisterEventSource(NULL, logident);
56 logmode = LOGMODE_NULL;
60 openlog(logident, LOG_CONS | LOG_PID, LOG_DAEMON);
69 void logger(int priority, const char *format, ...) {
76 vfprintf(stderr, format, ap);
77 fprintf(stderr, "\n");
81 fprintf(logfile, "%ld %s[%d]: ", time(NULL), logident, logpid);
82 vfprintf(logfile, format, ap);
83 fprintf(logfile, "\n");
90 char *messages[] = {message};
91 vsnprintf(message, sizeof(message), format, ap);
92 ReportEvent(loghandle, priority, 0, 0, NULL, 1, 0, messages, NULL);
97 vsyslog(priority, format, ap);
101 vsnprintf(message, sizeof(message), format, ap);
102 syslog(priority, "%s", message);
115 void closelogger(void) {
122 DeregisterEventSource(loghandle);