RTS API Documentation  1.10.11
switch_log.h
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  *
28  *
29  * switch_log.h -- Logger
30  *
31  */
32 /*! \file switch_log.h
33  \brief Simple Log
34 
35  Logging Routines
36 */
37 
38 #ifndef SWITCH_LOG_H
39 #define SWITCH_LOG_H
40 
41 #include <switch.h>
42 
44 ///\defgroup log Logger Routines
45 ///\ingroup core1
46 ///\{
47 /*! \brief Log Data
48  */
49  typedef struct {
50  /*! The complete log message */
51  char *data;
52  /*! The file where the message originated */
53  char file[80];
54  /*! The line number where the message originated */
55  uint32_t line;
56  /*! The function where the message originated */
57  char func[80];
58  /*! The log level of the message */
60  /*! The time when the log line was sent */
62  /*! A pointer to where the actual content of the message starts (skipping past the preformatted portion) */
63  char *content;
64  char *userdata;
65  /* To maintain abi, only add new elements to the end of this struct and do not delete any elements */
69  /* Log sequence */
70  int64_t sequence;
71  /* Optional extra log metadata */
74 
75 ///\{
76 /*! \brief JSON Log formatting data item
77  */
78 typedef struct {
79  const char *name;
80  const char *value;
82 
83 ///\{
84 /*! \brief JSON Log formatting data
85  */
86 typedef struct {
99  const char *custom_field_prefix;
103 
105 
106 /*!
107  \brief Convert a log node to JSON object. Destroy JSON object when finished.
108  \param node the node
109  \param log_level the log level
110  \param json_format the output format definition
111  \param char_vars optional channel variables to add to logs
112 */
113 SWITCH_DECLARE(cJSON *) switch_log_node_to_json(const switch_log_node_t *node, int log_level, switch_log_json_format_t *json_format, switch_event_t *chan_vars);
114 
115 /*!
116  \brief Initilize the logging engine
117  \param pool the memory pool to use
118  \note to be called at application startup by the core
119 */
121 
122 /*!
123  \brief Shut down the logging engine
124  \note to be called at application termination by the core
125 */
127 
128 #ifndef SWIG
129 /*!
130  \brief Write log data to the logging engine
131  \param channel the log channel to write to
132  \param file the current file
133  \param func the current function
134  \param line the current line
135  \param userdata ununsed
136  \param level the current log level
137  \param fmt desired format
138  \param ... variable args
139  \note there are channel macros to supply the first 4 parameters (SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_LOG_CLEAN, ...)
140  \see switch_types.h
141 */
142 SWITCH_DECLARE(void) switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file,
143  _In_z_ const char *func, _In_ int line,
144  _In_opt_z_ const char *userdata, _In_ switch_log_level_t level,
145  _In_z_ _Printf_format_string_ const char *fmt, ...) PRINTF_FUNCTION(7, 8);
146 /*!
147  \brief Write log data to the logging engine
148  \param channel the log channel to write to
149  \param file the current file
150  \param func the current function
151  \param line the current line
152  \param userdata ununsed
153  \param level the current log level
154  \param fmt desired format
155  \param ap variable args
156  \note there are channel macros to supply the first 4 parameters (SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_LOG_CLEAN, ...)
157  \see switch_types.h
158 */
159 SWITCH_DECLARE(void) switch_log_vprintf(_In_ switch_text_channel_t channel, _In_z_ const char *file,
160  _In_z_ const char *func, _In_ int line,
161  _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, const char *fmt, va_list ap);
162 /*!
163  \brief Write log data to the logging engine w/ optional JSON metadata
164  \param channel the log channel to write to
165  \param file the current file
166  \param func the current function
167  \param line the current line
168  \param userdata ununsed
169  \param level the current log level
170  \param meta log metadata - consumed by this function
171  \param fmt desired format
172  \param ... variable args
173  \note there are channel macros to supply the first 4 parameters (SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_LOG_CLEAN, ...)
174  \see switch_types.h
175 */
176 SWITCH_DECLARE(void) switch_log_meta_printf(switch_text_channel_t channel, const char *file, const char *func, int line,
177  const char *userdata, switch_log_level_t level, cJSON **meta, const char *fmt, ...) PRINTF_FUNCTION(8, 9);
178 
179 /*!
180  \brief Write log data to the logging engine w/ optional JSON metadata
181  \param channel the log channel to write to
182  \param file the current file
183  \param func the current function
184  \param line the current line
185  \param userdata ununsed
186  \param level the current log level
187  \param meta log metadata - consumed by this function
188  \param fmt desired format
189  \param ap variable args
190  \note there are channel macros to supply the first 4 parameters (SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_LOG_CLEAN, ...)
191  \see switch_types.h
192 */
194  _In_z_ const char *func, _In_ int line,
195  _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, cJSON **meta, const char *fmt, va_list ap);
196 #endif
197 /*!
198  \brief Shut down the logging engine
199  \note to be called at application termination by the core
200 */
203 
204 /*!
205  \brief Return the name of the specified log level
206  \param level the level
207  \return the name of the log level
208 */
210 
211 /*!
212  \brief Return the level number of the specified log level name
213  \param str the name of the level
214  \return the log level
215 */
217 
218 SWITCH_DECLARE(uint32_t) switch_log_str2mask(_In_z_ const char *str);
219 #define switch_log_check_mask(_mask, _level) (_mask & ((size_t)1 << _level))
220 
221 
224 
225 ///\}
227 #endif
228 /* For Emacs:
229  * Local Variables:
230  * mode:c
231  * indent-tabs-mode:t
232  * tab-width:4
233  * c-basic-offset:4
234  * End:
235  * For VIM:
236  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
237  */
switch_log_json_format_item_t sequence
Definition: switch_log.h:101
#define _Printf_format_string_
switch_text_channel_t
A target to write log/debug info to.
Log Data.
Definition: switch_log.h:49
#define SWITCH_END_EXTERN_C
Definition: switch.h:43
switch_log_json_format_item_t version
Definition: switch_log.h:87
switch_event_t * tags
Definition: switch_log.h:68
#define _Ret_z_
switch_bool_t
Definition: switch_types.h:437
switch_log_node_t * switch_log_node_dup(const switch_log_node_t *node)
Definition: switch_log.c:267
switch_memory_pool_t * pool
Representation of an event.
Definition: switch_event.h:80
switch_log_json_format_item_t pid
Definition: switch_log.h:92
uint32_t switch_log_str2mask(_In_z_ const char *str)
switch_log_json_format_item_t timestamp
Definition: switch_log.h:89
int cJSON_bool fmt
Definition: switch_cJSON.h:150
switch_log_json_format_item_t ident
Definition: switch_log.h:91
_Ret_z_ const char * switch_log_level2str(_In_ switch_log_level_t level)
Return the name of the specified log level.
switch_log_json_format_item_t line
Definition: switch_log.h:95
int64_t switch_time_t
Definition: switch_apr.h:188
switch_log_level_t switch_log_str2level(_In_z_ const char *str)
Return the level number of the specified log level name.
switch_log_json_format_item_t uuid
Definition: switch_log.h:93
switch_log_level_t slevel
Definition: switch_log.h:67
switch_status_t(* switch_log_function_t)(const switch_log_node_t *node, switch_log_level_t level)
Definition: switch_log.h:104
switch_log_json_format_item_t full_message
Definition: switch_log.h:97
#define _In_z_
JSON Log formatting data item.
Definition: switch_log.h:78
switch_time_t timestamp
Definition: switch_log.h:61
switch_status_t switch_log_shutdown(void)
Shut down the logging engine.
Definition: switch_log.c:799
switch_log_json_format_item_t short_message
Definition: switch_log.h:98
#define PRINTF_FUNCTION(fmtstr, vars)
int64_t sequence
Definition: switch_log.h:70
switch_status_t
Common return values.
void void switch_log_vprintf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, const char *fmt, va_list ap)
Write log data to the logging engine.
cJSON * switch_log_node_to_json(const switch_log_node_t *node, int log_level, switch_log_json_format_t *json_format, switch_event_t *chan_vars)
Convert a log node to JSON object. Destroy JSON object when finished.
Definition: switch_log.c:91
const char * custom_field_prefix
Definition: switch_log.h:99
Main Library Header.
switch_log_json_format_item_t level
Definition: switch_log.h:90
#define SWITCH_DECLARE(type)
void switch_log_meta_printf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *userdata, switch_log_level_t level, cJSON **meta, const char *fmt,...) PRINTF_FUNCTION(8
Write log data to the logging engine w/ optional JSON metadata.
void void switch_log_meta_vprintf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, cJSON **meta, const char *fmt, va_list ap)
Write log data to the logging engine w/ optional JSON metadata.
void switch_log_node_free(switch_log_node_t **pnode)
Definition: switch_log.c:300
switch_log_json_format_item_t host
Definition: switch_log.h:88
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_log_init(_In_ switch_memory_pool_t *pool, _In_ switch_bool_t colorize)
Initilize the logging engine.
#define _In_opt_z_
switch_status_t switch_log_unbind_logger(_In_ switch_log_function_t function)
struct fspr_pool_t switch_memory_pool_t
switch_text_channel_t channel
Definition: switch_log.h:66
JSON Log formatting data.
Definition: switch_log.h:86
switch_status_t switch_log_bind_logger(_In_ switch_log_function_t function, _In_ switch_log_level_t level, _In_ switch_bool_t is_console)
Shut down the logging engine.
switch_log_json_format_item_t file
Definition: switch_log.h:94
switch_log_level_t
Log Level Enumeration.
switch_log_level_t level
Definition: switch_log.h:59
#define _In_
#define SWITCH_BEGIN_EXTERN_C
Definition: switch.h:42