log framework
[protos/libecoli.git] / lib / ecoli_log.h
1 /*
2  * Copyright (c) 2016, Olivier MATZ <zer0@droids-corp.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of the University of California, Berkeley nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #ifndef ECOLI_LOG_
29 #define ECOLI_LOG_
30
31 #define EC_LOG_EMERG    0  /* system is unusable               */
32 #define EC_LOG_ALERT    1  /* action must be taken immediately */
33 #define EC_LOG_CRIT     2  /* critical conditions              */
34 #define EC_LOG_ERR      3  /* error conditions                 */
35 #define EC_LOG_WARNING  4  /* warning conditions               */
36 #define EC_LOG_NOTICE   5  /* normal but significant condition */
37 #define EC_LOG_INFO     6  /* informational                    */
38 #define EC_LOG_DEBUG    7  /* debug-level messages             */
39
40 #include <stdarg.h>
41
42 /* return -1 on error, len(s) on success */
43 typedef int (*ec_log_t)(unsigned int level, void *opaque, const char *str);
44
45 int ec_log_register(ec_log_t usr_log, void *opaque);
46 void ec_log_unregister(void);
47
48 /* same api than printf */
49 int ec_log(unsigned int level, const char *format, ...);
50 int ec_vlog(unsigned int level, const char *format, va_list ap);
51
52 /* default log handler for the library, use printf */
53 int ec_log_default(unsigned int level, void *opaque, const char *str);
54
55 #endif