libosmocore
0.9.3
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...) logp(ss, __FILE__, __LINE__, 0, fmt, ## args)
23
#define DEBUGPC(ss, fmt, args...) logp(ss, __FILE__, __LINE__, 1, fmt, ## args)
24
#else
25
#define DEBUGP(xss, fmt, args...)
26
#define DEBUGPC(ss, fmt, args...)
27
#endif
28
29
30
void
osmo_vlogp
(
int
subsys,
int
level,
const
char
*file,
int
line,
31
int
cont,
const
char
*format, va_list ap);
32
33
void
logp(
int
subsys,
const
char
*file,
int
line,
int
cont,
const
char
*format, ...) __attribute__ ((format (printf, 5, 6)));
34
41
#define LOGP(ss, level, fmt, args...) \
42
logp2(ss, level, __FILE__, __LINE__, 0, fmt, ##args)
43
50
#define LOGPC(ss, level, fmt, args...) \
51
logp2(ss, level, __FILE__, __LINE__, 1, fmt, ##args)
52
54
#define LOGL_DEBUG 1
55
#define LOGL_INFO 3
56
#define LOGL_NOTICE 5
57
#define LOGL_ERROR 7
58
#define LOGL_FATAL 8
60
#define LOG_FILTER_ALL 0x0001
61
62
/* logging levels defined by the library itself */
63
#define DLGLOBAL -1
64
#define DLLAPD -2
65
#define DLINP -3
66
#define DLMUX -4
67
#define DLMI -5
68
#define DLMIB -6
69
#define DLSMS -7
70
#define DLCTRL -8
71
#define DLGTP -9
72
#define DLSTATS -10
73
#define OSMO_NUM_DLIB 10
74
75
struct
log_category
{
76
uint8_t loglevel;
77
uint8_t enabled;
78
};
79
81
struct
log_info_cat
{
82
const
char
*
name
;
83
const
char
*
color
;
84
const
char
*
description
;
85
uint8_t
loglevel
;
86
uint8_t
enabled
;
87
};
88
90
struct
log_context
{
91
void
*ctx[
LOG_MAX_CTX
+1];
92
};
93
94
struct
log_target
;
95
97
typedef
int
log_filter
(
const
struct
log_context
*ctx,
98
struct
log_target
*target);
99
100
struct
log_info
;
101
struct
vty;
102
103
typedef
void
log_print_filters(
struct
vty *vty,
104
const
struct
log_info
*info,
105
const
struct
log_target
*tgt);
106
107
typedef
void
log_save_filters(
struct
vty *vty,
108
const
struct
log_info
*info,
109
const
struct
log_target
*tgt);
110
112
struct
log_info
{
113
/* \brief filter callback function */
114
log_filter
*filter_fn;
115
117
const
struct
log_info_cat
*
cat
;
119
unsigned
int
num_cat
;
121
unsigned
int
num_cat_user
;
122
123
/* \brief filter saving function */
124
log_save_filters *save_fn;
125
/* \brief filter saving function */
126
log_print_filters *print_fn;
127
};
128
130
enum
log_target_type
{
131
LOG_TGT_TYPE_VTY
,
132
LOG_TGT_TYPE_SYSLOG
,
133
LOG_TGT_TYPE_FILE
,
134
LOG_TGT_TYPE_STDERR
,
135
LOG_TGT_TYPE_STRRB
,
136
};
137
139
struct
log_target
{
140
struct
llist_head
entry
;
143
int
filter_map
;
145
void
*
filter_data
[
LOG_MAX_FILTERS
+1];
146
148
struct
log_category
*
categories
;
149
151
uint8_t
loglevel
;
153
unsigned
int
use_color
:1;
155
unsigned
int
print_timestamp
:1;
157
unsigned
int
print_filename
:1;
159
unsigned
int
print_category
:1;
161
unsigned
int
print_ext_timestamp
:1;
162
164
enum
log_target_type
type
;
165
166
union
{
167
struct
{
168
FILE *out;
169
const
char
*fname;
170
} tgt_file;
171
172
struct
{
173
int
priority;
174
int
facility;
175
} tgt_syslog;
176
177
struct
{
178
void
*vty;
179
} tgt_vty;
180
181
struct
{
182
void
*rb;
183
} tgt_rb;
184
};
185
192
void (*
output
) (
struct
log_target
*target,
unsigned
int
level,
193
const
char
*string);
194
};
195
196
/* use the above macros */
197
void
logp2(
int
subsys,
unsigned
int
level,
const
char
*file,
198
int
line,
int
cont,
const
char
*format, ...)
199
__attribute__ ((format (printf, 6, 7)));
200
int
log_init
(const struct
log_info
*inf,
void
*talloc_ctx);
201
202
/* context management */
203
void
log_reset_context
(
void
);
204
int
log_set_context
(uint8_t ctx,
void
*value);
205
206
/* filter on the targets */
207
void
log_set_all_filter
(struct
log_target
*target,
int
);
208
209
void
log_set_use_color
(struct
log_target
*target,
int
);
210
void
log_set_print_extended_timestamp
(struct
log_target
*target,
int
);
211
void
log_set_print_timestamp
(struct
log_target
*target,
int
);
212
void
log_set_print_filename
(struct
log_target
*target,
int
);
213
void
log_set_print_category
(struct
log_target
*target,
int
);
214
void
log_set_log_level
(struct
log_target
*target,
int
log_level);
215
void
log_parse_category_mask
(struct
log_target
*target, const
char
* mask);
216
int
log_parse_level
(const
char
*lvl);
217
const
char
*
log_level_str
(
unsigned
int
lvl);
218
int
log_parse_category
(const
char
*category);
219
void
log_set_category_filter
(struct
log_target
*target,
int
category,
220
int
enable,
int
level);
221
222
/* management of the targets */
223
struct
log_target
*
log_target_create
(
void
);
224
void
log_target_destroy
(struct
log_target
*target);
225
struct
log_target
*
log_target_create_stderr
(
void
);
226
struct
log_target
*
log_target_create_file
(const
char
*fname);
227
struct
log_target
*log_target_create_syslog(const
char
*ident,
int
option,
228
int
facility);
229
int
log_target_file_reopen
(struct
log_target
*tgt);
230
int
log_targets_reopen
(
void
);
231
232
void
log_add_target
(struct
log_target
*target);
233
void
log_del_target
(struct
log_target
*target);
234
235
/* Generate command string for VTY use */
236
const
char
*
log_vty_command_string
(const struct
log_info
*info);
237
const
char
*
log_vty_command_description
(const struct
log_info
*info);
238
239
struct
log_target
*
log_target_find
(
int
type
, const
char
*fname);
240
extern struct
llist_head
osmo_log_target_list;
241
include
osmocom
core
logging.h
Generated on Mon Jan 18 2016 13:12:49 for libosmocore by
1.8.1.2