libosmocore
0.9.3.20160317
Osmocom core library
Main Page
Modules
Data Structures
Files
File List
Globals
logging.h
Go to the documentation of this file.
1
#pragma once
2
9
#include <stdio.h>
10
#include <stdint.h>
11
#include <stdarg.h>
12
#include <osmocom/core/linuxlist.h>
13
15
#define LOG_MAX_CTX 8
16
17
#define LOG_MAX_FILTERS 8
18
19
#define DEBUG
20
21
#ifdef DEBUG
22
#define DEBUGP(ss, fmt, args...) \
23
do { \
24
if (log_check_level(ss, LOGL_DEBUG)) \
25
logp(ss, __FILE__, __LINE__, 0, fmt, ## args); \
26
} while(0)
27
28
#define DEBUGPC(ss, fmt, args...) \
29
do { \
30
if (log_check_level(ss, LOGL_DEBUG)) \
31
logp(ss, __FILE__, __LINE__, 1, fmt, ## args); \
32
} while(0)
33
34
#else
35
#define DEBUGP(xss, fmt, args...)
36
#define DEBUGPC(ss, fmt, args...)
37
#endif
38
39
40
void
osmo_vlogp
(
int
subsys,
int
level,
const
char
*file,
int
line,
41
int
cont,
const
char
*format, va_list ap);
42
43
void
logp(
int
subsys,
const
char
*file,
int
line,
int
cont,
const
char
*format, ...) __attribute__ ((format (printf, 5, 6)));
44
51
#define LOGP(ss, level, fmt, args...) \
52
do { \
53
if (log_check_level(ss, level)) \
54
logp2(ss, level, __FILE__, __LINE__, 0, fmt, ##args); \
55
} while(0)
56
63
#define LOGPC(ss, level, fmt, args...) \
64
do { \
65
if (log_check_level(ss, level)) \
66
logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args); \
67
} while(0)
68
70
#define LOGL_DEBUG 1
71
#define LOGL_INFO 3
72
#define LOGL_NOTICE 5
73
#define LOGL_ERROR 7
74
#define LOGL_FATAL 8
76
#define LOG_FILTER_ALL 0x0001
77
78
/* logging levels defined by the library itself */
79
#define DLGLOBAL -1
80
#define DLLAPD -2
81
#define DLINP -3
82
#define DLMUX -4
83
#define DLMI -5
84
#define DLMIB -6
85
#define DLSMS -7
86
#define DLCTRL -8
87
#define DLGTP -9
88
#define DLSTATS -10
89
#define OSMO_NUM_DLIB 10
90
91
struct
log_category
{
92
uint8_t loglevel;
93
uint8_t enabled;
94
};
95
97
struct
log_info_cat
{
98
const
char
*
name
;
99
const
char
*
color
;
100
const
char
*
description
;
101
uint8_t
loglevel
;
102
uint8_t
enabled
;
103
};
104
106
struct
log_context
{
107
void
*ctx[
LOG_MAX_CTX
+1];
108
};
109
110
struct
log_target
;
111
113
typedef
int
log_filter
(
const
struct
log_context
*ctx,
114
struct
log_target
*target);
115
116
struct
log_info
;
117
struct
vty;
118
119
typedef
void
log_print_filters(
struct
vty *vty,
120
const
struct
log_info
*info,
121
const
struct
log_target
*tgt);
122
123
typedef
void
log_save_filters(
struct
vty *vty,
124
const
struct
log_info
*info,
125
const
struct
log_target
*tgt);
126
128
struct
log_info
{
129
/* \brief filter callback function */
130
log_filter
*filter_fn;
131
133
const
struct
log_info_cat
*
cat
;
135
unsigned
int
num_cat
;
137
unsigned
int
num_cat_user
;
138
139
/* \brief filter saving function */
140
log_save_filters *save_fn;
141
/* \brief filter saving function */
142
log_print_filters *print_fn;
143
};
144
146
enum
log_target_type
{
147
LOG_TGT_TYPE_VTY
,
148
LOG_TGT_TYPE_SYSLOG
,
149
LOG_TGT_TYPE_FILE
,
150
LOG_TGT_TYPE_STDERR
,
151
LOG_TGT_TYPE_STRRB
,
152
};
153
155
struct
log_target
{
156
struct
llist_head
entry
;
159
int
filter_map
;
161
void
*
filter_data
[
LOG_MAX_FILTERS
+1];
162
164
struct
log_category
*
categories
;
165
167
uint8_t
loglevel
;
169
unsigned
int
use_color
:1;
171
unsigned
int
print_timestamp
:1;
173
unsigned
int
print_filename
:1;
175
unsigned
int
print_category
:1;
177
unsigned
int
print_ext_timestamp
:1;
178
180
enum
log_target_type
type
;
181
182
union
{
183
struct
{
184
FILE *out;
185
const
char
*fname;
186
} tgt_file;
187
188
struct
{
189
int
priority;
190
int
facility;
191
} tgt_syslog;
192
193
struct
{
194
void
*vty;
195
} tgt_vty;
196
197
struct
{
198
void
*rb;
199
} tgt_rb;
200
};
201
208
void (*
output
) (
struct
log_target
*target,
unsigned
int
level,
209
const
char
*string);
210
};
211
212
/* use the above macros */
213
void
logp2(
int
subsys,
unsigned
int
level,
const
char
*file,
214
int
line,
int
cont,
const
char
*format, ...)
215
__attribute__ ((format (printf, 6, 7)));
216
int
log_init
(const struct
log_info
*inf,
void
*talloc_ctx);
217
int
log_check_level
(
int
subsys,
unsigned
int
level);
218
219
/* context management */
220
void
log_reset_context
(
void
);
221
int
log_set_context
(uint8_t ctx,
void
*value);
222
223
/* filter on the targets */
224
void
log_set_all_filter
(struct
log_target
*target,
int
);
225
226
void
log_set_use_color
(struct
log_target
*target,
int
);
227
void
log_set_print_extended_timestamp
(struct
log_target
*target,
int
);
228
void
log_set_print_timestamp
(struct
log_target
*target,
int
);
229
void
log_set_print_filename
(struct
log_target
*target,
int
);
230
void
log_set_print_category
(struct
log_target
*target,
int
);
231
void
log_set_log_level
(struct
log_target
*target,
int
log_level);
232
void
log_parse_category_mask
(struct
log_target
*target, const
char
* mask);
233
int
log_parse_level
(const
char
*lvl);
234
const
char
*
log_level_str
(
unsigned
int
lvl);
235
int
log_parse_category
(const
char
*category);
236
void
log_set_category_filter
(struct
log_target
*target,
int
category,
237
int
enable,
int
level);
238
239
/* management of the targets */
240
struct
log_target
*
log_target_create
(
void
);
241
void
log_target_destroy
(struct
log_target
*target);
242
struct
log_target
*
log_target_create_stderr
(
void
);
243
struct
log_target
*
log_target_create_file
(const
char
*fname);
244
struct
log_target
*log_target_create_syslog(const
char
*ident,
int
option,
245
int
facility);
246
int
log_target_file_reopen
(struct
log_target
*tgt);
247
int
log_targets_reopen
(
void
);
248
249
void
log_add_target
(struct
log_target
*target);
250
void
log_del_target
(struct
log_target
*target);
251
252
/* Generate command string for VTY use */
253
const
char
*
log_vty_command_string
(const struct
log_info
*info);
254
const
char
*
log_vty_command_description
(const struct
log_info
*info);
255
256
struct
log_target
*
log_target_find
(
int
type
, const
char
*fname);
257
extern struct
llist_head
osmo_log_target_list;
258
include
osmocom
core
logging.h
Generated on Thu Mar 17 2016 19:51:35 for libosmocore by
1.8.1.2