]> code.delx.au - pulseaudio/blob - src/pulsecore/log.h
cli, log: Improve the set-log-target functionality
[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_type {
36 PA_LOG_STDERR, /* default */
37 PA_LOG_SYSLOG,
38 PA_LOG_NULL, /* to /dev/null */
39 PA_LOG_FILE, /* to a user specified file */
40 PA_LOG_NEWFILE, /* with an automatic suffix to avoid overwriting anything */
41 } pa_log_target_type_t;
42
43 typedef enum pa_log_level {
44 PA_LOG_ERROR = 0, /* Error messages */
45 PA_LOG_WARN = 1, /* Warning messages */
46 PA_LOG_NOTICE = 2, /* Notice messages */
47 PA_LOG_INFO = 3, /* Info messages */
48 PA_LOG_DEBUG = 4, /* debug message */
49 PA_LOG_LEVEL_MAX
50 } pa_log_level_t;
51
52 typedef enum pa_log_flags {
53 PA_LOG_COLORS = 0x01, /* Show colorful output */
54 PA_LOG_PRINT_TIME = 0x02, /* Show time */
55 PA_LOG_PRINT_FILE = 0x04, /* Show source file */
56 PA_LOG_PRINT_META = 0x08, /* Show extended location information */
57 PA_LOG_PRINT_LEVEL = 0x10, /* Show log level prefix */
58 } pa_log_flags_t;
59
60 typedef enum pa_log_merge {
61 PA_LOG_SET,
62 PA_LOG_UNSET,
63 PA_LOG_RESET
64 } pa_log_merge_t;
65
66 typedef struct {
67 pa_log_target_type_t type;
68 char *file;
69 } pa_log_target;
70
71 /* Set an identification for the current daemon. Used when logging to syslog. */
72 void pa_log_set_ident(const char *p);
73
74 /* Set a log target. */
75 int pa_log_set_target(pa_log_target *t);
76
77 /* Maximal log level */
78 void pa_log_set_level(pa_log_level_t l);
79
80 /* Set flags */
81 void pa_log_set_flags(pa_log_flags_t flags, pa_log_merge_t merge);
82
83 /* Set the file descriptor of the logging device.
84 Daemon conf is in charge of opening this device */
85 void pa_log_set_fd(int fd);
86
87 /* Enable backtrace */
88 void pa_log_set_show_backtrace(unsigned nlevels);
89
90 /* Skip the first backtrace frames */
91 void pa_log_set_skip_backtrace(unsigned nlevels);
92
93 void pa_log_level_meta(
94 pa_log_level_t level,
95 const char*file,
96 int line,
97 const char *func,
98 const char *format, ...) PA_GCC_PRINTF_ATTR(5,6);
99
100 void pa_log_levelv_meta(
101 pa_log_level_t level,
102 const char*file,
103 int line,
104 const char *func,
105 const char *format,
106 va_list ap);
107
108 void pa_log_level(
109 pa_log_level_t level,
110 const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
111
112 void pa_log_levelv(
113 pa_log_level_t level,
114 const char *format,
115 va_list ap);
116
117 pa_log_target *pa_log_target_new(pa_log_target_type_t type, const char *file);
118
119 void pa_log_target_free(pa_log_target *t);
120
121 pa_log_target *pa_log_parse_target(const char *string);
122
123 char *pa_log_target_to_string(const pa_log_target *t);
124
125 #if __STDC_VERSION__ >= 199901L
126
127 /* ISO varargs available */
128
129 #define pa_log_debug(...) pa_log_level_meta(PA_LOG_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__)
130 #define pa_log_info(...) pa_log_level_meta(PA_LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
131 #define pa_log_notice(...) pa_log_level_meta(PA_LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
132 #define pa_log_warn(...) pa_log_level_meta(PA_LOG_WARN, __FILE__, __LINE__, __func__, __VA_ARGS__)
133 #define pa_log_error(...) pa_log_level_meta(PA_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__)
134 #define pa_logl(level, ...) pa_log_level_meta(level, __FILE__, __LINE__, __func__, __VA_ARGS__)
135
136 #else
137
138 #define LOG_FUNC(suffix, level) \
139 PA_GCC_UNUSED static void pa_log_##suffix(const char *format, ...) { \
140 va_list ap; \
141 va_start(ap, format); \
142 pa_log_levelv_meta(level, NULL, 0, NULL, format, ap); \
143 va_end(ap); \
144 }
145
146 LOG_FUNC(debug, PA_LOG_DEBUG)
147 LOG_FUNC(info, PA_LOG_INFO)
148 LOG_FUNC(notice, PA_LOG_NOTICE)
149 LOG_FUNC(warn, PA_LOG_WARN)
150 LOG_FUNC(error, PA_LOG_ERROR)
151
152 #endif
153
154 #define pa_log pa_log_error
155
156 pa_bool_t pa_log_ratelimit(pa_log_level_t level);
157
158 #endif