7278dc684e36e6943ee5c355330a78926a936b67
[src/app-framework-binder.git] / include / afb / afb-verbosity.h
1 /*
2  * Copyright (C) 2016-2019 "IoT.bzh"
3  * Author: José Bollo <jose.bollo@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #pragma once
19
20 /** @defgroup AFB_LOGGING
21  *  @{ */
22
23 #define AFB_VERBOSITY_LEVEL_ERROR       0 /**< @deprecated in favor of @ref AFB_SYSLOG_LEVEL_ERROR */
24 #define AFB_VERBOSITY_LEVEL_WARNING     1 /**< @deprecated in favor of @ref AFB_SYSLOG_LEVEL_WARNING */
25 #define AFB_VERBOSITY_LEVEL_NOTICE      2 /**< @deprecated in favor of @ref AFB_SYSLOG_LEVEL_NOTICE */
26 #define AFB_VERBOSITY_LEVEL_INFO        3 /**< @deprecated in favor of @ref AFB_SYSLOG_LEVEL_INFO */
27 #define AFB_VERBOSITY_LEVEL_DEBUG       4 /**< @deprecated in favor of @ref AFB_SYSLOG_LEVEL_DEBUG */
28
29 #define AFB_SYSLOG_LEVEL_EMERGENCY      0
30 #define AFB_SYSLOG_LEVEL_ALERT          1
31 #define AFB_SYSLOG_LEVEL_CRITICAL       2
32 #define AFB_SYSLOG_LEVEL_ERROR          3
33 #define AFB_SYSLOG_LEVEL_WARNING        4
34 #define AFB_SYSLOG_LEVEL_NOTICE         5
35 #define AFB_SYSLOG_LEVEL_INFO           6
36 #define AFB_SYSLOG_LEVEL_DEBUG          7
37
38 #define AFB_VERBOSITY_LEVEL_WANT(verbosity,level)       ((verbosity) >= (level)) /**< @deprecated in favor of @ref AFB_SYSLOG_MASK_WANT */
39
40 #define AFB_VERBOSITY_LEVEL_WANT_ERROR(x)       AFB_VERBOSITY_LEVEL_WANT(x,AFB_VERBOSITY_LEVEL_ERROR) /**< @deprecated in favor of @ref AFB_SYSLOG_MASK_WANT_ERROR */
41 #define AFB_VERBOSITY_LEVEL_WANT_WARNING(x)     AFB_VERBOSITY_LEVEL_WANT(x,AFB_VERBOSITY_LEVEL_WARNING) /**< @deprecated in favor of @ref AFB_SYSLOG_MASK_WANT_WARNING */
42 #define AFB_VERBOSITY_LEVEL_WANT_NOTICE(x)      AFB_VERBOSITY_LEVEL_WANT(x,AFB_VERBOSITY_LEVEL_NOTICE) /**< @deprecated in favor of @ref AFB_SYSLOG_MASK_WANT_NOTICE */
43 #define AFB_VERBOSITY_LEVEL_WANT_INFO(x)        AFB_VERBOSITY_LEVEL_WANT(x,AFB_VERBOSITY_LEVEL_INFO) /**< @deprecated in favor of @ref AFB_SYSLOG_MASK_WANT_INFO */
44 #define AFB_VERBOSITY_LEVEL_WANT_DEBUG(x)       AFB_VERBOSITY_LEVEL_WANT(x,AFB_VERBOSITY_LEVEL_DEBUG) /**< @deprecated in favor of @ref AFB_SYSLOG_MASK_WANT_DEBUG */
45
46 #define AFB_SYSLOG_MASK_WANT(verbomask,level)   ((verbomask) & (1 << (level)))
47
48 #define AFB_SYSLOG_MASK_WANT_EMERGENCY(x)       AFB_SYSLOG_MASK_WANT(x,AFB_SYSLOG_LEVEL_EMERGENCY)
49 #define AFB_SYSLOG_MASK_WANT_ALERT(x)           AFB_SYSLOG_MASK_WANT(x,AFB_SYSLOG_LEVEL_ALERT)
50 #define AFB_SYSLOG_MASK_WANT_CRITICAL(x)        AFB_SYSLOG_MASK_WANT(x,AFB_SYSLOG_LEVEL_CRITICAL)
51 #define AFB_SYSLOG_MASK_WANT_ERROR(x)           AFB_SYSLOG_MASK_WANT(x,AFB_SYSLOG_LEVEL_ERROR)
52 #define AFB_SYSLOG_MASK_WANT_WARNING(x)         AFB_SYSLOG_MASK_WANT(x,AFB_SYSLOG_LEVEL_WARNING)
53 #define AFB_SYSLOG_MASK_WANT_NOTICE(x)          AFB_SYSLOG_MASK_WANT(x,AFB_SYSLOG_LEVEL_NOTICE)
54 #define AFB_SYSLOG_MASK_WANT_INFO(x)            AFB_SYSLOG_MASK_WANT(x,AFB_SYSLOG_LEVEL_INFO)
55 #define AFB_SYSLOG_MASK_WANT_DEBUG(x)           AFB_SYSLOG_MASK_WANT(x,AFB_SYSLOG_LEVEL_DEBUG)
56
57 #define AFB_SYSLOG_LEVEL_FROM_VERBOSITY(x)      ((x) + (AFB_SYSLOG_LEVEL_ERROR - AFB_VERBOSITY_LEVEL_ERROR))
58 #define AFB_SYSLOG_LEVEL_TO_VERBOSITY(x)        ((x) + (AFB_VERBOSITY_LEVEL_ERROR - AFB_SYSLOG_LEVEL_ERROR))
59
60 /**
61  * Transform a mask of verbosity to its significant level of verbosity.
62  * 
63  * @param verbomask the mask
64  * 
65  * @return the upper level that is not null, truncated to AFB_SYSLOG_LEVEL_DEBUG
66  * 
67  * @example _afb_verbomask_to_upper_level_(5) -> 2
68  * @example _afb_verbomask_to_upper_level_(16) -> 4
69  */
70 static inline int _afb_verbomask_to_upper_level_(int verbomask)
71 {
72         int result = 0;
73         while ((verbomask >>= 1) && result < AFB_SYSLOG_LEVEL_DEBUG)
74                 result++;
75         return result;
76 }
77
78 /** @} */