1 /*
2  * This file is part of the Sofia-SIP package
3  *
4  * Copyright (C) 2005 Nokia Corporation.
5  *
6  * Contact: Pekka Pessi <pekka.pessi@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24 
25 /**@ingroup su_log
26  * @file sofia-sip/su_log.h   SU logging interface
27  *
28  * @author Pekka Pessi <Pekka.Pessi@nokia.com>.
29  *
30  * @date Created: Thu Feb 22 18:09:02 2001 ppessi
31  *
32  */
33 
34 #ifndef SU_LOG_T
35 /** Defined when the type #su_log_t has been defined. */
36 #define SU_LOG_T
37 /** Type of log structure. */
38 typedef struct su_log_s su_log_t;
39 #endif
40 
41 #ifndef SU_LOG_H_NEED_SU_LOG_T
42 
43 #ifndef SU_LOG_H
44 /** Defined when <sofia-sip/su_log.h> has been included. */
45 #define SU_LOG_H
46 
47 #include <stdarg.h>
48 
49 #ifndef SU_CONFIG_H
50 #include <sofia-sip/su_config.h>
51 #endif
52 
53 SOFIA_BEGIN_DECLS
54 
55 #ifdef _MSC_VER
56 #define __SOFIA_FUNC__ __FUNCTION__
57 #else
58 #define __SOFIA_FUNC__ (const char *)__func__
59 #endif
60 
61 
62 
63 
64 /** Prototype for logging function */
65 typedef void (su_logger_f)(void *stream, char const *fmt, va_list ap);
66 
67 /** Log object. */
68 struct su_log_s {
69   int          log_size;
70   char const  *log_name;
71   char const  *log_env;
72   unsigned     log_default;
73   unsigned     log_level;
74   int          log_init;
75 
76   su_logger_f *log_logger;
77   void        *log_stream;
78 };
79 
80 enum { SU_LOG_MAX = 9 };
81 
82 /** Initialize a su_log_t structure */
83 #define SU_LOG_INIT(name, env, level) \
84   { sizeof(su_log_t), name, env, level, SU_LOG_MAX, 0, NULL, NULL, }
85 
86 SOFIAPUBFUN void su_log(char const *fmt, ...)
87   __attribute__ ((__format__ (printf, 1, 2)));
88 
89 SOFIAPUBFUN void _su_llog(su_log_t *log, unsigned level, const char *file, const char *func, int line, char const *fmt, ...)
90   __attribute__ ((__format__ (printf, 6, 7)));
91 SOFIAPUBFUN void _su_vllog(su_log_t *log, unsigned level, const char *file, const char *func, int line,
92 			  char const *fmt, va_list ap);
93 SOFIAPUBFUN void su_log_redirect(su_log_t *log, su_logger_f *f, void *stream);
94 SOFIAPUBFUN void su_log_set_level(su_log_t *log, unsigned level);
95 SOFIAPUBFUN void su_log_soft_set_level(su_log_t *log, unsigned level);
96 SOFIAPUBFUN void su_log_init(su_log_t *log);
97 
98 SOFIAPUBVAR su_log_t su_log_default[];
99 SOFIAPUBVAR su_log_t su_log_global[];
100 
101 /** Log the latest su error message */
102 SOFIAPUBFUN void su_perror(char const *s);
103 
104 #define su_llog(_l, _ll, _f, ...) _su_llog(_l, _ll, __FILE__, __SOFIA_FUNC__, __LINE__, _f, __VA_ARGS__)
105 #define su_vllog(_l, _ll, _f, ...) _su_vllog(_l, _ll, __FILE__, __SOFIA_FUNC__, __LINE__, _f, __VA_ARGS__)
106 
107 /** Log the su error message. */
108 SOFIAPUBFUN void su_perror2(char const *s, int errcode);
109 
110 SOFIA_END_DECLS
111 
112 #endif
113 
114 #endif /* !defined(SU_LOG_H_NEED_SU_LOG_T) */
115