]> git.ipfire.org Git - thirdparty/systemd.git/blob - logging.h
[PATCH] add i2c-dev to the list of devices without a bus
[thirdparty/systemd.git] / logging.h
1 /*
2 * logging.h
3 *
4 * Simple logging functions that can be compiled away into nothing.
5 *
6 * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
7 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24 #ifndef LOGGING_H
25 #define LOGGING_H
26
27 #define info(format, arg...) do { } while (0)
28 #define dbg(format, arg...) do { } while (0)
29 #define dbg_parse(format, arg...) do { } while (0)
30 #define logging_init(foo) do { } while (0)
31 #define logging_close(foo) do { } while (0)
32
33 #ifdef LOG
34 #include <stdarg.h>
35 #include <unistd.h>
36 #include <syslog.h>
37
38 #define LOGNAME_SIZE 42
39
40 #undef info
41 #define info(format, arg...) \
42 do { \
43 log_message(LOG_INFO , format , ## arg); \
44 } while (0)
45
46 #ifdef DEBUG
47 #undef dbg
48 #define dbg(format, arg...) \
49 do { \
50 log_message(LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \
51 } while (0)
52 #endif
53
54 /* Parser needs it's own debugging statement, we usually don't care about this at all */
55 #ifdef DEBUG_PARSER
56 #undef dbg_parse
57 #define dbg_parse(format, arg...) \
58 do { \
59 log_message(LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \
60 } while (0)
61 #endif
62
63 extern void log_message(int level, const char *format, ...)
64 __attribute__ ((format (printf, 2, 3)));
65
66 /* each program that uses syslog must declare this variable somewhere */
67 extern unsigned char logname[LOGNAME_SIZE];
68
69 #undef logging_init
70 static inline void logging_init(char *program_name)
71 {
72 snprintf(logname, LOGNAME_SIZE,"%s[%d]", program_name, getpid());
73 openlog(logname, 0, LOG_DAEMON);
74 }
75
76 #undef logging_close
77 static inline void logging_close(void)
78 {
79 closelog();
80 }
81
82 #endif /* LOG */
83
84 #endif