2 * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
3 * Author: José Bollo <jose.bollo@iot.bzh>
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 /** @defgroup AFB_LOGGING
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 */
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
38 #define AFB_VERBOSITY_LEVEL_WANT(verbosity,level) ((verbosity) >= (level)) /**< @deprecated in favor of @ref AFB_SYSLOG_MASK_WANT */
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 */
46 #define AFB_SYSLOG_MASK_WANT(verbomask,level) ((verbomask) & (1 << (level)))
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)
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))
61 * Transform a mask of verbosity to its significant level of verbosity.
63 * @param verbomask the mask
65 * @return the upper level that is not null, truncated to AFB_SYSLOG_LEVEL_DEBUG
67 * @example _afb_verbomask_to_upper_level_(5) -> 2
68 * @example _afb_verbomask_to_upper_level_(16) -> 4
70 static inline int _afb_verbomask_to_upper_level_(int verbomask)
73 while ((verbomask >>= 1) && result < AFB_SYSLOG_LEVEL_DEBUG)