]> code.delx.au - pulseaudio/blob - src/pulsecore/log.h
Merge branch 'master' of ssh://rootserver/home/lennart/git/public/pulseaudio
[pulseaudio] / src / pulsecore / log.h
1 #ifndef foologhfoo
2 #define foologhfoo
3
4 /***
5 This file is part of PulseAudio.
6
7 Copyright 2004-2006 Lennart Poettering
8 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9
10 PulseAudio is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published
12 by the Free Software Foundation; either version 2.1 of the License,
13 or (at your option) any later version.
14
15 PulseAudio is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with PulseAudio; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 USA.
24 ***/
25
26 #include <stdarg.h>
27 #include <stdlib.h>
28
29 #include <pulsecore/macro.h>
30 #include <pulse/gccmacro.h>
31
32 /* A simple logging subsystem */
33
34 /* Where to log to */
35 typedef enum pa_log_target {
36 PA_LOG_STDERR, /* default */
37 PA_LOG_SYSLOG,
38 PA_LOG_NULL, /* to /dev/null */
39 PA_LOG_TARGET_MAX
40 } pa_log_target_t;
41
42 typedef enum pa_log_level {
43 PA_LOG_ERROR = 0, /* Error messages */
44 PA_LOG_WARN = 1, /* Warning messages */
45 PA_LOG_NOTICE = 2, /* Notice messages */
46 PA_LOG_INFO = 3, /* Info messages */
47 PA_LOG_DEBUG = 4, /* debug message */
48 PA_LOG_LEVEL_MAX
49 } pa_log_level_t;
50
51 typedef enum pa_log_flags {
52 PA_LOG_COLORS = 0x01, /* Show colorful output */
53 PA_LOG_PRINT_TIME = 0x02, /* Show time */
54 PA_LOG_PRINT_FILE = 0x04, /* Show source file */
55 PA_LOG_PRINT_META = 0x08, /* Show extended locaton information */
56 PA_LOG_PRINT_LEVEL = 0x10, /* Show log level prefix */
57 } pa_log_flags_t;
58
59 typedef enum pa_log_merge {
60 PA_LOG_SET,
61 PA_LOG_UNSET,
62 PA_LOG_RESET
63 } pa_log_merge_t;
64
65 /* Set an identification for the current daemon. Used when logging to syslog. */
66 void pa_log_set_ident(const char *p);
67
68 /* Set a log target. */
69 void pa_log_set_target(pa_log_target_t t);
70
71 /* Maximal log level */
72 void pa_log_set_level(pa_log_level_t l);
73
74 /* Set flags */
75 void pa_log_set_flags(pa_log_flags_t flags, pa_log_merge_t merge);
76
77 /* Enable backtrace */
78 void pa_log_set_show_backtrace(unsigned nlevels);
79
80 void pa_log_level_meta(
81 pa_log_level_t level,
82 const char*file,
83 int line,
84 const char *func,
85 const char *format, ...) PA_GCC_PRINTF_ATTR(5,6);
86
87 void pa_log_levelv_meta(
88 pa_log_level_t level,
89 const char*file,
90 int line,
91 const char *func,
92 const char *format,
93 va_list ap);
94
95 void pa_log_level(
96 pa_log_level_t level,
97 const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
98
99 void pa_log_levelv(
100 pa_log_level_t level,
101 const char *format,
102 va_list ap);
103
104 #if __STDC_VERSION__ >= 199901L
105
106 /* ISO varargs available */
107
108 #define pa_log_debug(...) pa_log_level_meta(PA_LOG_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__)
109 #define pa_log_info(...) pa_log_level_meta(PA_LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
110 #define pa_log_notice(...) pa_log_level_meta(PA_LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
111 #define pa_log_warn(...) pa_log_level_meta(PA_LOG_WARN, __FILE__, __LINE__, __func__, __VA_ARGS__)
112 #define pa_log_error(...) pa_log_level_meta(PA_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__)
113
114 #else
115
116 #define LOG_FUNC(suffix, level) \
117 PA_GCC_UNUSED static void pa_log_##suffix(const char *format, ...) { \
118 va_list ap; \
119 va_start(ap, format); \
120 pa_log_levelv_meta(level, NULL, 0, NULL, format, ap); \
121 va_end(ap); \
122 }
123
124 LOG_FUNC(debug, PA_LOG_DEBUG)
125 LOG_FUNC(info, PA_LOG_INFO)
126 LOG_FUNC(notice, PA_LOG_NOTICE)
127 LOG_FUNC(warn, PA_LOG_WARN)
128 LOG_FUNC(error, PA_LOG_ERROR)
129
130 #endif
131
132 #define pa_log pa_log_error
133
134 pa_bool_t pa_log_ratelimit(void);
135
136 #endif