chenqiyang
2021-08-20 7b95fb4d4549d3452ee17165236186afc1f2b393
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*
 * Copyright (c) 2010-2019 Belledonne Communications SARL.
 *
 * This file is part of Liblinphone.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
 
#ifndef _LINPHONE_LOG_H_
#define _LINPHONE_LOG_H_
 
#include "types.h"
#include "defs.h"
 
#ifdef __cplusplus
extern "C" {
#endif
 
/**
 * @addtogroup logging
 * @{
 */
 
/**
 * @brief Singleton class giving access to logging features.
 */
typedef struct _LinphoneLoggingService LinphoneLoggingService;
 
/**
 * @brief Listener for #LinphoneLoggingService.
 */
typedef struct _LinphoneLoggingServiceCbs LinphoneLoggingServiceCbs;
 
/**
 * @brief Verbosity levels of log messages.
 */
typedef enum _LinphoneLogLevel {
    LinphoneLogLevelDebug   = 1,    /**< @brief Level for debug messages. */
    LinphoneLogLevelTrace   = 1<<1, /**< @brief Level for traces. */
    LinphoneLogLevelMessage = 1<<2, /**< @brief Level for information messages. */
    LinphoneLogLevelWarning = 1<<3, /**< @brief Level for warning messages. */
    LinphoneLogLevelError   = 1<<4, /**< @brief Level for error messages. */
    LinphoneLogLevelFatal   = 1<<5  /**< @brief Level for fatal error messages. */
} LinphoneLogLevel;
 
/**
 * @brief Type of callbacks called each time liblinphone write a log message.
 * 
 * @param log_service A pointer on the logging service singleton.
 * @param domain A string describing which sub-library of liblinphone the message is coming from.
 * @param lev Verbosity level of the message.
 * @param message Content of the message.
 */
typedef void (*LinphoneLoggingServiceCbsLogMessageWrittenCb)(LinphoneLoggingService *log_service, const char *domain, LinphoneLogLevel lev, const char *message);
 
 
 
 
 
/**
 * @brief Gets the singleton logging service object.
 * 
 * The singleton is automatically instantiated if it hasn't
 * been done yet.
 * 
 * @return A pointer on the singleton.
 */
LINPHONE_PUBLIC LinphoneLoggingService *linphone_logging_service_get(void);
 
/**
 * @brief Increases the reference counter.
 */
LINPHONE_PUBLIC LinphoneLoggingService *linphone_logging_service_ref(LinphoneLoggingService *service);
 
/**
 * @brief Decreases the reference counter and destroy the object
 * if the counter reaches 0.
 */
LINPHONE_PUBLIC void linphone_logging_service_unref(LinphoneLoggingService *service);
 
/**
 * @brief Gets the logging service listener.
 * @deprecated Use add_callbacks / remove_callbacks instead
 */
LINPHONE_PUBLIC LinphoneLoggingServiceCbs *linphone_logging_service_get_callbacks(const LinphoneLoggingService *log_service);
 
/**
 * Adds a callback object to the list of listeners
 * @param log_service the LinphoneLoggingService object
 * @param cbs the LinphoneLoggingServiceCbs to add
 */
LINPHONE_PUBLIC void linphone_logging_service_add_callbacks(LinphoneLoggingService *log_service, LinphoneLoggingServiceCbs *cbs);
 
/**
 * Removes a callback object from the list of listeners
 * @param log_service the LinphoneLoggingService object
 * @param cbs the LinphoneLoggingServiceCbs to remove
 */
LINPHONE_PUBLIC void linphone_logging_service_remove_callbacks(LinphoneLoggingService *log_service, LinphoneLoggingServiceCbs *cbs);
 
/**
 * Returns the current callbacks being called while iterating on callbacks
 * @param log_service the LinphoneLoggingService object
 * @return A pointer to the current LinphoneLoggingServiceCbs object
 */
LINPHONE_PUBLIC LinphoneLoggingServiceCbs *linphone_logging_service_get_current_callbacks(const LinphoneLoggingService *log_service);
 
/**
 * @brief Set the verbosity of the log.
 * 
 * For instance, a level of #LinphoneLogLevelMessage will let pass fatal, error, warning and message-typed messages
 * whereas trace and debug messages will be dumped out.
 */
LINPHONE_PUBLIC void linphone_logging_service_set_log_level(LinphoneLoggingService *log_service, LinphoneLogLevel level);
 
/**
 * @brief Sets the types of messages that will be authorized to be written in the log.
 * @param log_service The logging service singleton.
 * @param mask Example: #LinphoneLogLevelMessage|#LinphoneLogLevelError will ONLY let pass message-typed and error messages.
 * @note Calling that function reset the log level that has been specified by #linphone_logging_service_set_log_level().
 */
LINPHONE_PUBLIC void linphone_logging_service_set_log_level_mask(LinphoneLoggingService *log_service, unsigned int mask);
 
/**
 * @brief Gets the log level mask.
 */
LINPHONE_PUBLIC unsigned int linphone_logging_service_get_log_level_mask(const LinphoneLoggingService *log_service);
 
/**
 * @brief Enables logging in a file.
 * 
 * That function enables an internal log handler that writes log messages in
 * log-rotated files.
 * 
 * @param dir Directory where to create the distinct parts of the log.
 * @param filename Name of the log file.
 * @param max_size The maximal size of each part of the log. The log rotating is triggered
 * each time the currently opened log part reach that limit.
 */
LINPHONE_PUBLIC void linphone_logging_service_set_log_file(const LinphoneLoggingService *service, const char *dir, const char *filename, size_t max_size);
 
/**
 * @brief Set the domain where application logs are written (for example with #linphone_logging_service_message()).
 * @param log_service The logging service singleton.
 * @param domain The domain.
 * @note The domain is mandatory to write logs. This needs to be set before setting the log level.
 */
LINPHONE_PUBLIC void linphone_logging_service_set_domain(LinphoneLoggingService *log_service, const char *domain);
 
/**
 * @brief Get the domain where application logs are written (for example with #linphone_logging_service_message()).
 * @param log_service The logging service singleton.
 */
LINPHONE_PUBLIC const char *linphone_logging_service_get_domain(LinphoneLoggingService *log_service);
 
/**
 * @brief Write a LinphoneLogLevelDebug message to the logs.
 * @param log_service The logging service singleton.
 * @param msg The log message.
 */
LINPHONE_PUBLIC void linphone_logging_service_debug(LinphoneLoggingService *log_service, const char *msg);
 
/**
 * @brief Write a LinphoneLogLevelTrace message to the logs.
 * @param log_service The logging service singleton.
 * @param msg The log message.
 */
LINPHONE_PUBLIC void linphone_logging_service_trace(LinphoneLoggingService *log_service, const char *msg);
 
/**
 * @brief Write a LinphoneLogLevelMessage message to the logs.
 * @param log_service The logging service singleton.
 * @param msg The log message.
 */
LINPHONE_PUBLIC void linphone_logging_service_message(LinphoneLoggingService *log_service, const char *msg);
 
/**
 * @brief Write a LinphoneLogLevelWarning message to the logs.
 * @param log_service The logging service singleton.
 * @param msg The log message.
 */
LINPHONE_PUBLIC void linphone_logging_service_warning(LinphoneLoggingService *log_service, const char *msg);
 
/**
 * @brief Write a LinphoneLogLevelError message to the logs.
 * @param log_service The logging service singleton.
 * @param msg The log message.
 */
LINPHONE_PUBLIC void linphone_logging_service_error(LinphoneLoggingService *log_service, const char *msg);
 
/**
 * @brief Write a LinphoneLogLevelFatal message to the logs.
 * @param log_service The logging service singleton.
 * @param msg The log message.
 */
LINPHONE_PUBLIC void linphone_logging_service_fatal(LinphoneLoggingService *log_service, const char *msg);
 
/**
 * @brief Increases the reference counter.
 */
LINPHONE_PUBLIC LinphoneLoggingServiceCbs *linphone_logging_service_cbs_ref(LinphoneLoggingServiceCbs *cbs);
 
/**
 * @brief Decreases the reference counter.
 * 
 * The object is automatically destroyed once the counter reach 0.
 */
LINPHONE_PUBLIC void linphone_logging_service_cbs_unref(LinphoneLoggingServiceCbs *cbs);
 
/**
 * @brief Sets the callback to call each time liblinphone writes a log message.
 */
LINPHONE_PUBLIC void linphone_logging_service_cbs_set_log_message_written(LinphoneLoggingServiceCbs *cbs, LinphoneLoggingServiceCbsLogMessageWrittenCb cb);
 
/**
 * @brief Gets the value of the message event callback.
 */
LINPHONE_PUBLIC LinphoneLoggingServiceCbsLogMessageWrittenCb linphone_logging_service_cbs_get_log_message_written(const LinphoneLoggingServiceCbs *cbs);
 
/**
 * @brief Pass a pointer on a custom object.
 * 
 * That pointer can be get back by callbacks by using #linphone_logging_service_get_cbs() and #linphone_logging_service_cbs_get_user_data().
 */
LINPHONE_PUBLIC void linphone_logging_service_cbs_set_user_data(LinphoneLoggingServiceCbs *cbs, void *user_data);
 
/**
 * @brief Gets the user_data pointer back.
 */
LINPHONE_PUBLIC void *linphone_logging_service_cbs_get_user_data(const LinphoneLoggingServiceCbs *cbs);
 
 
/**
 * @}
 */
 
#ifdef __cplusplus
}
#endif
 
#endif // _LINPHONE_LOG_H_