2 * Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
13 struct loglevel_name_value
{
19 const struct loglevel_name_value loglevel_values
[] = {
20 { .name
= "EMERG", .value
= LTTNG_LOGLEVEL_EMERG
},
21 { .name
= "TRACE_EMERG", .value
= LTTNG_LOGLEVEL_EMERG
},
22 { .name
= "ALERT", .value
= LTTNG_LOGLEVEL_ALERT
},
23 { .name
= "TRACE_ALERT", .value
= LTTNG_LOGLEVEL_ALERT
},
24 { .name
= "CRIT", .value
= LTTNG_LOGLEVEL_CRIT
},
25 { .name
= "TRACE_CRIT", .value
= LTTNG_LOGLEVEL_CRIT
},
26 { .name
= "ERR", .value
= LTTNG_LOGLEVEL_ERR
},
27 { .name
= "TRACE_ERR", .value
= LTTNG_LOGLEVEL_ERR
},
28 { .name
= "WARNING", .value
= LTTNG_LOGLEVEL_WARNING
},
29 { .name
= "TRACE_WARNING", .value
= LTTNG_LOGLEVEL_WARNING
},
30 { .name
= "NOTICE", .value
= LTTNG_LOGLEVEL_NOTICE
},
31 { .name
= "TRACE_NOTICE", .value
= LTTNG_LOGLEVEL_NOTICE
},
32 { .name
= "INFO", .value
= LTTNG_LOGLEVEL_INFO
},
33 { .name
= "TRACE_INFO", .value
= LTTNG_LOGLEVEL_INFO
},
34 { .name
= "DEBUG_SYSTEM", .value
= LTTNG_LOGLEVEL_DEBUG_SYSTEM
},
35 { .name
= "TRACE_DEBUG_SYSTEM", .value
= LTTNG_LOGLEVEL_DEBUG_SYSTEM
},
36 { .name
= "SYSTEM", .value
= LTTNG_LOGLEVEL_DEBUG_SYSTEM
},
37 { .name
= "DEBUG_PROGRAM", .value
= LTTNG_LOGLEVEL_DEBUG_PROGRAM
},
38 { .name
= "TRACE_DEBUG_PROGRAM", .value
= LTTNG_LOGLEVEL_DEBUG_PROGRAM
},
39 { .name
= "PROGRAM", .value
= LTTNG_LOGLEVEL_DEBUG_PROGRAM
},
40 { .name
= "DEBUG_PROCESS", .value
= LTTNG_LOGLEVEL_DEBUG_PROCESS
},
41 { .name
= "TRACE_DEBUG_PROCESS", .value
= LTTNG_LOGLEVEL_DEBUG_PROCESS
},
42 { .name
= "PROCESS", .value
= LTTNG_LOGLEVEL_DEBUG_PROCESS
},
43 { .name
= "DEBUG_MODULE", .value
= LTTNG_LOGLEVEL_DEBUG_MODULE
},
44 { .name
= "TRACE_DEBUG_MODULE", .value
= LTTNG_LOGLEVEL_DEBUG_MODULE
},
45 { .name
= "MODULE", .value
= LTTNG_LOGLEVEL_DEBUG_MODULE
},
46 { .name
= "DEBUG_UNIT", .value
= LTTNG_LOGLEVEL_DEBUG_UNIT
},
47 { .name
= "TRACE_DEBUG_UNIT", .value
= LTTNG_LOGLEVEL_DEBUG_UNIT
},
48 { .name
= "UNIT", .value
= LTTNG_LOGLEVEL_DEBUG_UNIT
},
49 { .name
= "DEBUG_FUNCTION", .value
= LTTNG_LOGLEVEL_DEBUG_FUNCTION
},
50 { .name
= "TRACE_DEBUG_FUNCTION", .value
= LTTNG_LOGLEVEL_DEBUG_FUNCTION
},
51 { .name
= "FUNCTION", .value
= LTTNG_LOGLEVEL_DEBUG_FUNCTION
},
52 { .name
= "DEBUG_LINE", .value
= LTTNG_LOGLEVEL_DEBUG_LINE
},
53 { .name
= "TRACE_DEBUG_LINE", .value
= LTTNG_LOGLEVEL_DEBUG_LINE
},
54 { .name
= "LINE", .value
= LTTNG_LOGLEVEL_DEBUG_LINE
},
55 { .name
= "DEBUG", .value
= LTTNG_LOGLEVEL_DEBUG
},
56 { .name
= "TRACE_DEBUG", .value
= LTTNG_LOGLEVEL_DEBUG
},
60 const struct loglevel_name_value loglevel_log4j_values
[] = {
61 { .name
= "OFF", .value
= LTTNG_LOGLEVEL_LOG4J_OFF
},
62 { .name
= "LOG4J_OFF", .value
= LTTNG_LOGLEVEL_LOG4J_OFF
},
63 { .name
= "FATAL", .value
= LTTNG_LOGLEVEL_LOG4J_FATAL
},
64 { .name
= "LOG4J_FATAL", .value
= LTTNG_LOGLEVEL_LOG4J_FATAL
},
65 { .name
= "ERROR", .value
= LTTNG_LOGLEVEL_LOG4J_ERROR
},
66 { .name
= "LOG4J_ERROR", .value
= LTTNG_LOGLEVEL_LOG4J_ERROR
},
67 { .name
= "WARN", .value
= LTTNG_LOGLEVEL_LOG4J_WARN
},
68 { .name
= "LOG4J_WARN", .value
= LTTNG_LOGLEVEL_LOG4J_WARN
},
69 { .name
= "INFO", .value
= LTTNG_LOGLEVEL_LOG4J_INFO
},
70 { .name
= "LOG4J_INFO", .value
= LTTNG_LOGLEVEL_LOG4J_INFO
},
71 { .name
= "DEBUG", .value
= LTTNG_LOGLEVEL_LOG4J_DEBUG
},
72 { .name
= "LOG4J_DEBUG", .value
= LTTNG_LOGLEVEL_LOG4J_DEBUG
},
73 { .name
= "TRACE", .value
= LTTNG_LOGLEVEL_LOG4J_TRACE
},
74 { .name
= "LOG4J_TRACE", .value
= LTTNG_LOGLEVEL_LOG4J_TRACE
},
75 { .name
= "ALL", .value
= LTTNG_LOGLEVEL_LOG4J_ALL
},
76 { .name
= "LOG4J_ALL", .value
= LTTNG_LOGLEVEL_LOG4J_ALL
},
80 const struct loglevel_name_value loglevel_jul_values
[] = {
81 { .name
= "OFF", .value
= LTTNG_LOGLEVEL_JUL_OFF
},
82 { .name
= "JUL_OFF", .value
= LTTNG_LOGLEVEL_JUL_OFF
},
83 { .name
= "SEVERE", .value
= LTTNG_LOGLEVEL_JUL_SEVERE
},
84 { .name
= "JUL_SEVERE", .value
= LTTNG_LOGLEVEL_JUL_SEVERE
},
85 { .name
= "WARNING", .value
= LTTNG_LOGLEVEL_JUL_WARNING
},
86 { .name
= "JUL_WARNING", .value
= LTTNG_LOGLEVEL_JUL_WARNING
},
87 { .name
= "INFO", .value
= LTTNG_LOGLEVEL_JUL_INFO
},
88 { .name
= "JUL_INFO", .value
= LTTNG_LOGLEVEL_JUL_INFO
},
89 { .name
= "CONFIG", .value
= LTTNG_LOGLEVEL_JUL_CONFIG
},
90 { .name
= "JUL_CONFIG", .value
= LTTNG_LOGLEVEL_JUL_CONFIG
},
91 { .name
= "FINE", .value
= LTTNG_LOGLEVEL_JUL_FINE
},
92 { .name
= "JUL_FINE", .value
= LTTNG_LOGLEVEL_JUL_FINE
},
93 { .name
= "FINER", .value
= LTTNG_LOGLEVEL_JUL_FINER
},
94 { .name
= "JUL_FINER", .value
= LTTNG_LOGLEVEL_JUL_FINER
},
95 { .name
= "FINEST", .value
= LTTNG_LOGLEVEL_JUL_FINEST
},
96 { .name
= "JUL_FINEST", .value
= LTTNG_LOGLEVEL_JUL_FINEST
},
97 { .name
= "ALL", .value
= LTTNG_LOGLEVEL_JUL_ALL
},
98 { .name
= "JUL_ALL", .value
= LTTNG_LOGLEVEL_JUL_ALL
},
102 const struct loglevel_name_value loglevel_python_values
[] = {
103 { .name
= "CRITICAL", .value
= LTTNG_LOGLEVEL_PYTHON_CRITICAL
},
104 { .name
= "PYTHON_CRITICAL", .value
= LTTNG_LOGLEVEL_PYTHON_CRITICAL
},
105 { .name
= "ERROR", .value
= LTTNG_LOGLEVEL_PYTHON_ERROR
},
106 { .name
= "PYTHON_ERROR", .value
= LTTNG_LOGLEVEL_PYTHON_ERROR
},
107 { .name
= "WARNING", .value
= LTTNG_LOGLEVEL_PYTHON_WARNING
},
108 { .name
= "PYTHON_WARNING", .value
= LTTNG_LOGLEVEL_PYTHON_WARNING
},
109 { .name
= "INFO", .value
= LTTNG_LOGLEVEL_PYTHON_INFO
},
110 { .name
= "PYTHON_INFO", .value
= LTTNG_LOGLEVEL_PYTHON_INFO
},
111 { .name
= "DEBUG", .value
= LTTNG_LOGLEVEL_PYTHON_DEBUG
},
112 { .name
= "PYTNON_DEBUG", .value
= LTTNG_LOGLEVEL_PYTHON_DEBUG
},
113 { .name
= "NOTSET", .value
= LTTNG_LOGLEVEL_PYTHON_NOTSET
},
114 { .name
= "PYTHON_NOTSET", .value
= LTTNG_LOGLEVEL_PYTHON_NOTSET
},
118 bool string_equal_insensitive(const char *a
, const char *b
)
120 return strcasecmp(a
, b
) == 0;
124 int lookup_value_from_name(const struct loglevel_name_value values
[],
125 size_t values_count
, const char *name
)
134 for (i
= 0; i
< values_count
; i
++) {
135 if (string_equal_insensitive(values
[i
].name
, name
)) {
137 ret
= values
[i
].value
;
146 static bool loglevel_parse_range_string_common(const char *str
,
147 const struct loglevel_name_value
*nvs
,
154 const struct loglevel_name_value
*nv
;
156 for (i
= 0; i
< nvs_count
; i
++) {
159 if (strncmp(str
, nv
->name
, strlen(nv
->name
)) == 0) {
164 if (i
== nvs_count
) {
169 str
+= strlen(nv
->name
);
177 if (strncmp(str
, "..", strlen("..")) != 0) {
184 *max
= LTTNG_LOGLEVEL_EMERG
;
189 for (i
= 0; i
< nvs_count
; i
++) {
192 if (strcmp(str
, nv
->name
) == 0) {
197 if (i
== nvs_count
) {
213 int loglevel_name_to_value(const char *name
, enum lttng_loglevel
*loglevel
)
215 int ret
= lookup_value_from_name(loglevel_values
,
216 ARRAY_SIZE(loglevel_values
), name
);
219 *loglevel
= (typeof(*loglevel
)) ret
;
226 bool loglevel_parse_range_string(const char *str
,
227 enum lttng_loglevel
*min
,
228 enum lttng_loglevel
*max
)
230 int min_int
, max_int
;
231 bool ret
= loglevel_parse_range_string_common(str
, loglevel_values
,
232 ARRAY_SIZE(loglevel_values
), &min_int
, &max_int
);
234 *min
= (lttng_loglevel
) min_int
;
235 *max
= (lttng_loglevel
) max_int
;
240 int loglevel_log4j_name_to_value(
241 const char *name
, enum lttng_loglevel_log4j
*loglevel
)
243 int ret
= lookup_value_from_name(loglevel_log4j_values
,
244 ARRAY_SIZE(loglevel_log4j_values
),
248 *loglevel
= (typeof(*loglevel
)) ret
;
255 bool loglevel_log4j_parse_range_string(const char *str
,
256 enum lttng_loglevel_log4j
*min
,
257 enum lttng_loglevel_log4j
*max
)
259 int min_int
, max_int
;
260 bool ret
= loglevel_parse_range_string_common(str
,
261 loglevel_log4j_values
,
262 ARRAY_SIZE(loglevel_log4j_values
), &min_int
, &max_int
);
264 *min
= (lttng_loglevel_log4j
) min_int
;
265 *max
= (lttng_loglevel_log4j
) max_int
;
270 int loglevel_jul_name_to_value(
271 const char *name
, enum lttng_loglevel_jul
*loglevel
)
273 int ret
= lookup_value_from_name(loglevel_jul_values
,
274 ARRAY_SIZE(loglevel_jul_values
),
278 *loglevel
= (typeof(*loglevel
)) ret
;
285 bool loglevel_jul_parse_range_string(const char *str
,
286 enum lttng_loglevel_jul
*min
,
287 enum lttng_loglevel_jul
*max
)
289 int min_int
, max_int
;
290 bool ret
= loglevel_parse_range_string_common(str
, loglevel_jul_values
,
291 ARRAY_SIZE(loglevel_jul_values
), &min_int
, &max_int
);
293 *min
= (lttng_loglevel_jul
) min_int
;
294 *max
= (lttng_loglevel_jul
) max_int
;
299 int loglevel_python_name_to_value(
300 const char *name
, enum lttng_loglevel_python
*loglevel
)
302 int ret
= lookup_value_from_name(loglevel_python_values
,
303 ARRAY_SIZE(loglevel_python_values
),
307 *loglevel
= (typeof(*loglevel
)) ret
;
314 bool loglevel_python_parse_range_string(const char *str
,
315 enum lttng_loglevel_python
*min
,
316 enum lttng_loglevel_python
*max
)
318 int min_int
, max_int
;
319 bool ret
= loglevel_parse_range_string_common(str
,
320 loglevel_python_values
,
321 ARRAY_SIZE(loglevel_python_values
), &min_int
, &max_int
);
323 *min
= (lttng_loglevel_python
) min_int
;
324 *max
= (lttng_loglevel_python
) max_int
;
330 const char *lookup_name_from_value(const struct loglevel_name_value values
[],
331 size_t values_count
, int loglevel
)
334 const char *name
= NULL
;
336 for (i
= 0; i
< values_count
; i
++) {
337 if (values
[i
].value
== loglevel
) {
339 name
= values
[i
].name
;
348 const char *loglevel_value_to_name(int loglevel
)
350 return lookup_name_from_value(
351 loglevel_values
, ARRAY_SIZE(loglevel_values
), loglevel
);
354 const char *loglevel_log4j_value_to_name(int loglevel
)
356 return lookup_name_from_value(loglevel_log4j_values
,
357 ARRAY_SIZE(loglevel_log4j_values
), loglevel
);
360 const char *loglevel_jul_value_to_name(int loglevel
)
362 return lookup_name_from_value(loglevel_jul_values
,
363 ARRAY_SIZE(loglevel_jul_values
), loglevel
);
366 const char *loglevel_python_value_to_name(int loglevel
)
368 return lookup_name_from_value(loglevel_python_values
,
369 ARRAY_SIZE(loglevel_python_values
), loglevel
);