Add copyright notices to all relevant files. (based on svn log)
[profile/ivi/pulseaudio.git] / src / pulsecore / log.h
1 #ifndef foologhfoo
2 #define foologhfoo
3
4 /* $Id$ */
5
6 /***
7   This file is part of PulseAudio.
8
9   Copyright 2004-2006 Lennart Poettering
10   Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
11
12   PulseAudio is free software; you can redistribute it and/or modify
13   it under the terms of the GNU Lesser General Public License as published
14   by the Free Software Foundation; either version 2 of the License,
15   or (at your option) any later version.
16
17   PulseAudio is distributed in the hope that it will be useful, but
18   WITHOUT ANY WARRANTY; without even the implied warranty of
19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20   General Public License for more details.
21
22   You should have received a copy of the GNU Lesser General Public License
23   along with PulseAudio; if not, write to the Free Software
24   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25   USA.
26 ***/
27
28 #include <stdarg.h>
29 #include <stdlib.h>
30 #include <pulsecore/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_USER,    /* to user specified function */
39     PA_LOG_NULL     /* to /dev/null */
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 /* Set an identification for the current daemon. Used when logging to syslog. */
52 void pa_log_set_ident(const char *p);
53
54 /* Set another log target. If t is PA_LOG_USER you may specify a function that is called every log string */
55 void pa_log_set_target(pa_log_target_t t, void (*func)(pa_log_level_t t, const char*s));
56
57 /* Minimal log level */
58 void pa_log_set_maximal_level(pa_log_level_t l);
59
60 void pa_log_level_meta(
61         pa_log_level_t level,
62         const char*file,
63         int line,
64         const char *func,
65         const char *format, ...) PA_GCC_PRINTF_ATTR(5,6);
66 void pa_log_levelv_meta(
67         pa_log_level_t level,
68         const char*file,
69         int line,
70         const char *func,
71         const char *format,
72         va_list ap);
73
74 void pa_log_level(pa_log_level_t level, const char *format, ...) PA_GCC_PRINTF_ATTR(2,3);
75 void pa_log_levelv(pa_log_level_t level, const char *format, va_list ap);
76
77 #if __STDC_VERSION__ >= 199901L
78
79 /* ISO varargs available */
80
81 #define pa_log_debug(...)  pa_log_level_meta(PA_LOG_DEBUG,  __FILE__, __LINE__, __func__, __VA_ARGS__)
82 #define pa_log_info(...)   pa_log_level_meta(PA_LOG_INFO,   __FILE__, __LINE__, __func__, __VA_ARGS__)
83 #define pa_log_notice(...) pa_log_level_meta(PA_LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
84 #define pa_log_warn(...)   pa_log_level_meta(PA_LOG_WARN,   __FILE__, __LINE__, __func__, __VA_ARGS__)
85 #define pa_log_error(...)  pa_log_level_meta(PA_LOG_ERROR,  __FILE__, __LINE__, __func__, __VA_ARGS__)
86
87 #else
88
89 #define LOG_FUNC(suffix, level) \
90 PA_GCC_UNUSED static void pa_log_##suffix(const char *format, ...) { \
91     va_list ap; \
92     va_start(ap, format); \
93     pa_log_levelv_meta(level, NULL, 0, NULL, format, ap); \
94     va_end(ap); \
95 }
96
97 LOG_FUNC(debug, PA_LOG_DEBUG)
98 LOG_FUNC(info, PA_LOG_INFO)
99 LOG_FUNC(notice, PA_LOG_NOTICE)
100 LOG_FUNC(warn, PA_LOG_WARN)
101 LOG_FUNC(error, PA_LOG_ERROR)
102
103 #endif
104
105 #define pa_log pa_log_error
106
107 #endif