4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
38 #define ENV_LOGLEVEL "POLYP_LOG"
40 static char *log_ident = NULL;
41 static pa_log_target_t log_target = PA_LOG_STDERR;
42 static void (*user_log_func)(pa_log_level_t l, const char *s) = NULL;
43 static pa_log_level_t maximal_level = PA_LOG_NOTICE;
46 static const int level_to_syslog[] = {
47 [PA_LOG_ERROR] = LOG_ERR,
48 [PA_LOG_WARN] = LOG_WARNING,
49 [PA_LOG_NOTICE] = LOG_NOTICE,
50 [PA_LOG_INFO] = LOG_INFO,
51 [PA_LOG_DEBUG] = LOG_DEBUG
55 void pa_log_set_ident(const char *p) {
59 log_ident = pa_xstrdup(p);
62 void pa_log_set_maximal_level(pa_log_level_t l) {
63 assert(l < PA_LOG_LEVEL_MAX);
67 void pa_log_set_target(pa_log_target_t t, void (*func)(pa_log_level_t l, const char*s)) {
68 assert(t == PA_LOG_USER || !func);
73 void pa_log_levelv(pa_log_level_t level, const char *format, va_list ap) {
75 assert(level < PA_LOG_LEVEL_MAX);
77 if ((e = getenv(ENV_LOGLEVEL)))
78 maximal_level = atoi(e);
80 if (level > maximal_level)
85 vfprintf(stderr, format, ap);
90 openlog(log_ident ? log_ident : "???", LOG_PID, LOG_USER);
91 vsyslog(level_to_syslog[level], format, ap);
97 char *t = pa_vsprintf_malloc(format, ap);
98 assert(user_log_func);
99 user_log_func(level, t);
110 void pa_log_level(pa_log_level_t level, const char *format, ...) {
112 va_start(ap, format);
113 pa_log_levelv(level, format, ap);
117 void pa_log_debug(const char *format, ...) {
119 va_start(ap, format);
120 pa_log_levelv(PA_LOG_DEBUG, format, ap);
124 void pa_log_info(const char *format, ...) {
126 va_start(ap, format);
127 pa_log_levelv(PA_LOG_INFO, format, ap);
131 void pa_log_notice(const char *format, ...) {
133 va_start(ap, format);
134 pa_log_levelv(PA_LOG_INFO, format, ap);
138 void pa_log_warn(const char *format, ...) {
140 va_start(ap, format);
141 pa_log_levelv(PA_LOG_WARN, format, ap);
145 void pa_log_error(const char *format, ...) {
147 va_start(ap, format);
148 pa_log_levelv(PA_LOG_ERROR, format, ap);