forked from signalwire/freeswitch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_log.h
More file actions
199 lines (181 loc) · 6.42 KB
/
Copy pathswitch_log.h
File metadata and controls
199 lines (181 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2014, Anthony Minessale II <[email protected]>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <[email protected]>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <[email protected]>
*
*
* switch_log.h -- Logger
*
*/
/*! \file switch_log.h
\brief Simple Log
Logging Routines
*/
#ifndef SWITCH_LOG_H
#define SWITCH_LOG_H
#include <switch.h>
SWITCH_BEGIN_EXTERN_C
///\defgroup log Logger Routines
///\ingroup core1
///\{
/*! \brief Log Data
*/
typedef struct {
/*! The complete log message */
char *data;
/*! The file where the message originated */
char file[80];
/*! The line number where the message originated */
uint32_t line;
/*! The function where the message originated */
char func[80];
/*! The log level of the message */
switch_log_level_t level;
/*! The time when the log line was sent */
switch_time_t timestamp;
/*! A pointer to where the actual content of the message starts (skipping past the preformatted portion) */
char *content;
char *userdata;
/* To maintain abi, only add new elements to the end of this struct and do not delete any elements */
switch_text_channel_t channel;
switch_log_level_t slevel;
switch_event_t *tags;
} switch_log_node_t;
///\{
/*! \brief JSON Log formatting data item
*/
typedef struct {
const char *name;
const char *value;
} switch_log_json_format_item_t;
///\{
/*! \brief JSON Log formatting data
*/
typedef struct {
switch_log_json_format_item_t version;
switch_log_json_format_item_t host;
switch_log_json_format_item_t timestamp;
switch_log_json_format_item_t level;
switch_log_json_format_item_t ident;
switch_log_json_format_item_t pid;
switch_log_json_format_item_t uuid;
switch_log_json_format_item_t file;
switch_log_json_format_item_t line;
switch_log_json_format_item_t function;
switch_log_json_format_item_t full_message;
switch_log_json_format_item_t short_message;
const char *custom_field_prefix;
double timestamp_divisor;
} switch_log_json_format_t;
typedef switch_status_t (*switch_log_function_t) (const switch_log_node_t *node, switch_log_level_t level);
/*!
\brief Convert a log node to JSON object. Destroy JSON object when finished.
\param node the node
\param log_level the log level
\param json_format the output format definition
\param char_vars optional channel variables to add to logs
*/
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);
/*!
\brief Initilize the logging engine
\param pool the memory pool to use
\note to be called at application startup by the core
*/
SWITCH_DECLARE(switch_status_t) switch_log_init(_In_ switch_memory_pool_t *pool, _In_ switch_bool_t colorize);
/*!
\brief Shut down the logging engine
\note to be called at application termination by the core
*/
SWITCH_DECLARE(switch_status_t) switch_log_shutdown(void);
#ifndef SWIG
/*!
\brief Write log data to the logging engine
\param channel the log channel to write to
\param file the current file
\param func the current function
\param line the current line
\param userdata ununsed
\param level the current log level
\param fmt desired format
\param ... variable args
\note there are channel macros to supply the first 4 parameters (SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_LOG_CLEAN, ...)
\see switch_types.h
*/
SWITCH_DECLARE(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, 8);
/*!
\brief Write log data to the logging engine
\param channel the log channel to write to
\param file the current file
\param func the current function
\param line the current line
\param userdata ununsed
\param level the current log level
\param fmt desired format
\param ap variable args
\note there are channel macros to supply the first 4 parameters (SWITCH_CHANNEL_LOG, SWITCH_CHANNEL_LOG_CLEAN, ...)
\see switch_types.h
*/
SWITCH_DECLARE(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);
#endif
/*!
\brief Shut down the logging engine
\note to be called at application termination by the core
*/
SWITCH_DECLARE(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);
SWITCH_DECLARE(switch_status_t) switch_log_unbind_logger(_In_ switch_log_function_t function);
/*!
\brief Return the name of the specified log level
\param level the level
\return the name of the log level
*/
_Ret_z_ SWITCH_DECLARE(const char *) switch_log_level2str(_In_ switch_log_level_t level);
/*!
\brief Return the level number of the specified log level name
\param str the name of the level
\return the log level
*/
SWITCH_DECLARE(switch_log_level_t) switch_log_str2level(_In_z_ const char *str);
SWITCH_DECLARE(uint32_t) switch_log_str2mask(_In_z_ const char *str);
#define switch_log_check_mask(_mask, _level) (_mask & ((size_t)1 << _level))
SWITCH_DECLARE(switch_log_node_t *) switch_log_node_dup(const switch_log_node_t *node);
SWITCH_DECLARE(void) switch_log_node_free(switch_log_node_t **pnode);
///\}
SWITCH_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/