Asterisk - The Open Source Telephony Project  18.5.0
logger_category.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2020, Sangoma Technologies Corporation
5  *
6  * Kevin Harwell <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 #ifndef ASTERISK_LOGGER_CATEGORY_H
19 #define ASTERISK_LOGGER_CATEGORY_H
20 
21 #include "asterisk/logger.h"
22 
23 /*!
24  * Logger category is enabled
25  */
26 #define AST_LOG_CATEGORY_ENABLED -1
27 
28 /*!
29  * Logger category is disabled
30  */
31 #define AST_LOG_CATEGORY_DISABLED 0
32 
33 /*!
34  * \brief Load/Initialize system wide logger category functionality
35  *
36  * \retval 0 Success, -1 Failure
37  *
38  * \since 16.14
39  * \since 17.8
40  * \since 18.0
41  */
42 int ast_logger_category_load(void);
43 
44 /*!
45  * \brief Unload system wide logger category functionality
46  *
47  * \retval 0 Success, -1 Failure
48  *
49  * \since 16.14
50  * \since 17.8
51  * \since 18.0
52  */
54 
55 /*!
56  * \brief Register a debug level logger category
57  *
58  * \param name The name of the category
59  * \param id The unique id of the category
60  *
61  * \retval 0 if failed to register/retrieve an id. Otherwise it returns the id
62  * for the registered category.
63  *
64  * \since 16.14
65  * \since 17.8
66  * \since 18.0
67  */
68 uintmax_t ast_debug_category_register(const char *name);
69 
70 /*!
71  * \brief Un-register a debug level logger category
72  *
73  * \retval 0 Success, -1 Failure
74  *
75  * \since 16.14
76  * \since 17.8
77  * \since 18.0
78  */
79 int ast_debug_category_unregister(const char *name);
80 
81 /*!
82  * \brief Set the debug category's sublevel
83  *
84  * Statements are output at a specified sublevel. Typically any number greater
85  * than or equal to 0. Other acceptable values include AST_LOG_CATEGORY_ENABLED
86  * and AST_LOG_CATEGORY_DISABLED.
87  *
88  * \param name The name of the category
89  * \param sublevel The debug sublevel output number
90  *
91  * \retval 0 Success, -1 Failure
92  *
93  * \since 16.14
94  * \since 17.8
95  * \since 18.0
96  */
97 int ast_debug_category_set_sublevel(const char *name, int sublevel);
98 
99 /*!
100  * \brief Set one or more debug category's sublevel.
101  *
102  * Accepts an array of category names, and optional associated sublevels. Sublevels can
103  * be associated with a name by using a ':' as a separator. For example:
104  *
105  * <category name>:<category sublevel>
106  *
107  * The given default sublevel is used if no sublevel is associated with a name.
108  *
109  * \param names An array of category names
110  * \param size The size of the array (number of elements)
111  * \param default_sublevel The sublevel value to use if one is not associated with a name
112  *
113  * \retval 0 Success, -1 Failure
114  *
115  * \since 16.14
116  * \since 17.8
117  * \since 18.0
118  */
119 int ast_debug_category_set_sublevels(const char * const *names, size_t size, int default_sublevel);
120 
121 /*!
122  * \brief Add a unique (no duplicates) result to a request for completion for debug categories.
123  *
124  * \param argv A list of already completed options
125  * \param argc The number of already completed options
126  * \param word The word to complete
127  * \param state The state
128  *
129  * \retval 0 Success, -1 Failure
130  *
131  * \since 16.14
132  * \since 17.8
133  * \since 18.0
134  */
135 char *ast_debug_category_complete(const char * const *argv, int argc, const char *word, int state);
136 
137 /*!
138  * \brief Check if a debug category is enabled, and allowed to output
139  *
140  * \note If more than one id is specified then if even one is allowed "true"
141  * is returned.
142  *
143  * \param sublevel Current set sublevel must be this sublevel or less
144  * \param ids One or more unique category ids to check
145  *
146  * \retval 1 if allowed, 0 if not allowed
147  *
148  * \since 16.14
149  * \since 17.8
150  * \since 18.0
151 */
152 int ast_debug_category_is_allowed(int sublevel, uintmax_t ids);
153 
154 /*!
155  * \brief Log for a debug category.
156  *
157  * This will output log data for debug under the following conditions:
158  *
159  * 1. The specified sublevel is at, or below the current system debug level
160  * 2. At least one of the given category ids is enabled AND
161  * a. The category sublevel is enabled OR the given sublevel is at, or
162  * below a category's specified sublevel.
163  *
164  * \param sublevel The minimum level to output at
165  * \param ids One or more unique category ids to output for
166  *
167  * \since 16.14
168  * \since 17.8
169  * \since 18.0
170  */
171 #define ast_debug_category(sublevel, ids, ...) \
172  do { \
173  if (DEBUG_ATLEAST(sublevel) || ast_debug_category_is_allowed(sublevel, ids)) { \
174  ast_log(AST_LOG_DEBUG, __VA_ARGS__); \
175  } \
176  } while (0)
177 
178 #endif /* ASTERISK_LOGGER_CATEGORY_H */
int ast_debug_category_set_sublevel(const char *name, int sublevel)
Set the debug category&#39;s sublevel.
int ast_debug_category_is_allowed(int sublevel, uintmax_t ids)
Check if a debug category is enabled, and allowed to output.
int ast_logger_category_unload(void)
Unload system wide logger category functionality.
char * ast_debug_category_complete(const char *const *argv, int argc, const char *word, int state)
Add a unique (no duplicates) result to a request for completion for debug categories.
int ast_debug_category_set_sublevels(const char *const *names, size_t size, int default_sublevel)
Set one or more debug category&#39;s sublevel.
static const char name[]
Definition: cdr_mysql.c:74
Support for logging to various files, console and syslog Configuration in file logger.conf.
int ast_debug_category_unregister(const char *name)
Un-register a debug level logger category.
uintmax_t ast_debug_category_register(const char *name)
Register a debug level logger category.
short word
int ast_logger_category_load(void)
Load/Initialize system wide logger category functionality.