Merge branch 'master' of https://github.com/iotbzh/afb-daemon
[src/app-framework-binder.git] / src / verbose.h
1 /*
2  Copyright (C) 2016 "IoT.bzh"
3
4  author: José Bollo <jose.bollo@iot.bzh>
5
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9
10      http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 */
18
19 #pragma once
20
21 #if !defined(VERBOSE_WITH_SYSLOG)
22
23   extern int verbosity;
24   extern void verbose(int level, const char *file, int line, const char *fmt, ...);
25
26 # define ERROR(...)   do{if(verbosity>=0)verbose(3,__FILE__,__LINE__,__VA_ARGS__);}while(0)
27 # define WARNING(...) do{if(verbosity>=1)verbose(4,__FILE__,__LINE__,__VA_ARGS__);}while(0)
28 # define NOTICE(...)  do{if(verbosity>=1)verbose(5,__FILE__,__LINE__,__VA_ARGS__);}while(0)
29 # define INFO(...)    do{if(verbosity>=2)verbose(6,__FILE__,__LINE__,__VA_ARGS__);}while(0)
30 # define DEBUG(...)   do{if(verbosity>=3)verbose(7,__FILE__,__LINE__,__VA_ARGS__);}while(0)
31 # define LOGUSER(app) NOTICE("Starting user application %s",app)
32 # define LOGAUTH(app) NOTICE("Starting auth application %s",app)
33
34 #else /* VERBOSE_WITH_SYSLOG is defined */
35
36 # include <syslog.h>
37
38 # define LOGUSER(app) openlog(app,LOG_PERROR,LOG_USER)
39 # define LOGAUTH(app) openlog(app,LOG_PERROR,LOG_AUTH)
40
41 # if !defined(NDEBUG)
42
43     extern int verbosity;
44 #   define ERROR(...)   syslog(LOG_ERR,__VA_ARGS__)
45 #   define WARNING(...) do{if(verbosity)syslog(LOG_WARNING,__VA_ARGS__);}while(0)
46 #   define NOTICE(...)  do{if(verbosity)syslog(LOG_NOTICE,__VA_ARGS__);}while(0)
47 #   define INFO(...)    do{if(verbosity>1)syslog(LOG_INFO,__VA_ARGS__);}while(0)
48 #   define DEBUG(...)   do{if(verbosity>2)syslog(LOG_DEBUG,__VA_ARGS__);}while(0)
49
50 # else
51
52     extern void verbose_error(const char *file, int line);
53 #   define ERROR(...)   verbose_error(__FILE__,__LINE__)
54 #   define WARNING(...) do{/*nothing*/}while(0)
55 #   define NOTICE(...)  do{/*nothing*/}while(0)
56 #   define INFO(...)    do{/*nothing*/}while(0)
57 #   define DEBUG(...)   do{/*nothing*/}while(0)
58
59 # endif
60
61 #endif
62