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