2 * Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
14 struct loglevel_name_value
{
20 const struct loglevel_name_value loglevel_values
[] = {
21 { .name
= "EMERG", .value
= LTTNG_LOGLEVEL_EMERG
},
22 { .name
= "TRACE_EMERG", .value
= LTTNG_LOGLEVEL_EMERG
},
23 { .name
= "ALERT", .value
= LTTNG_LOGLEVEL_ALERT
},
24 { .name
= "TRACE_ALERT", .value
= LTTNG_LOGLEVEL_ALERT
},
25 { .name
= "CRIT", .value
= LTTNG_LOGLEVEL_CRIT
},
26 { .name
= "TRACE_CRIT", .value
= LTTNG_LOGLEVEL_CRIT
},
27 { .name
= "ERR", .value
= LTTNG_LOGLEVEL_ERR
},
28 { .name
= "TRACE_ERR", .value
= LTTNG_LOGLEVEL_ERR
},
29 { .name
= "WARNING", .value
= LTTNG_LOGLEVEL_WARNING
},
30 { .name
= "TRACE_WARNING", .value
= LTTNG_LOGLEVEL_WARNING
},
31 { .name
= "NOTICE", .value
= LTTNG_LOGLEVEL_NOTICE
},
32 { .name
= "TRACE_NOTICE", .value
= LTTNG_LOGLEVEL_NOTICE
},
33 { .name
= "INFO", .value
= LTTNG_LOGLEVEL_INFO
},
34 { .name
= "TRACE_INFO", .value
= LTTNG_LOGLEVEL_INFO
},
35 { .name
= "DEBUG_SYSTEM", .value
= LTTNG_LOGLEVEL_DEBUG_SYSTEM
},
36 { .name
= "TRACE_DEBUG_SYSTEM", .value
= LTTNG_LOGLEVEL_DEBUG_SYSTEM
},
37 { .name
= "SYSTEM", .value
= LTTNG_LOGLEVEL_DEBUG_SYSTEM
},
38 { .name
= "DEBUG_PROGRAM", .value
= LTTNG_LOGLEVEL_DEBUG_PROGRAM
},
39 { .name
= "TRACE_DEBUG_PROGRAM", .value
= LTTNG_LOGLEVEL_DEBUG_PROGRAM
},
40 { .name
= "PROGRAM", .value
= LTTNG_LOGLEVEL_DEBUG_PROGRAM
},
41 { .name
= "DEBUG_PROCESS", .value
= LTTNG_LOGLEVEL_DEBUG_PROCESS
},
42 { .name
= "TRACE_DEBUG_PROCESS", .value
= LTTNG_LOGLEVEL_DEBUG_PROCESS
},
43 { .name
= "PROCESS", .value
= LTTNG_LOGLEVEL_DEBUG_PROCESS
},
44 { .name
= "DEBUG_MODULE", .value
= LTTNG_LOGLEVEL_DEBUG_MODULE
},
45 { .name
= "TRACE_DEBUG_MODULE", .value
= LTTNG_LOGLEVEL_DEBUG_MODULE
},
46 { .name
= "MODULE", .value
= LTTNG_LOGLEVEL_DEBUG_MODULE
},
47 { .name
= "DEBUG_UNIT", .value
= LTTNG_LOGLEVEL_DEBUG_UNIT
},
48 { .name
= "TRACE_DEBUG_UNIT", .value
= LTTNG_LOGLEVEL_DEBUG_UNIT
},
49 { .name
= "UNIT", .value
= LTTNG_LOGLEVEL_DEBUG_UNIT
},
50 { .name
= "DEBUG_FUNCTION", .value
= LTTNG_LOGLEVEL_DEBUG_FUNCTION
},
51 { .name
= "TRACE_DEBUG_FUNCTION", .value
= LTTNG_LOGLEVEL_DEBUG_FUNCTION
},
52 { .name
= "FUNCTION", .value
= LTTNG_LOGLEVEL_DEBUG_FUNCTION
},
53 { .name
= "DEBUG_LINE", .value
= LTTNG_LOGLEVEL_DEBUG_LINE
},
54 { .name
= "TRACE_DEBUG_LINE", .value
= LTTNG_LOGLEVEL_DEBUG_LINE
},
55 { .name
= "LINE", .value
= LTTNG_LOGLEVEL_DEBUG_LINE
},
56 { .name
= "DEBUG", .value
= LTTNG_LOGLEVEL_DEBUG
},
57 { .name
= "TRACE_DEBUG", .value
= LTTNG_LOGLEVEL_DEBUG
},
61 const struct loglevel_name_value loglevel_log4j_values
[] = {
62 { .name
= "OFF", .value
= LTTNG_LOGLEVEL_LOG4J_OFF
},
63 { .name
= "LOG4J_OFF", .value
= LTTNG_LOGLEVEL_LOG4J_OFF
},
64 { .name
= "FATAL", .value
= LTTNG_LOGLEVEL_LOG4J_FATAL
},
65 { .name
= "LOG4J_FATAL", .value
= LTTNG_LOGLEVEL_LOG4J_FATAL
},
66 { .name
= "ERROR", .value
= LTTNG_LOGLEVEL_LOG4J_ERROR
},
67 { .name
= "LOG4J_ERROR", .value
= LTTNG_LOGLEVEL_LOG4J_ERROR
},
68 { .name
= "WARN", .value
= LTTNG_LOGLEVEL_LOG4J_WARN
},
69 { .name
= "LOG4J_WARN", .value
= LTTNG_LOGLEVEL_LOG4J_WARN
},
70 { .name
= "INFO", .value
= LTTNG_LOGLEVEL_LOG4J_INFO
},
71 { .name
= "LOG4J_INFO", .value
= LTTNG_LOGLEVEL_LOG4J_INFO
},
72 { .name
= "DEBUG", .value
= LTTNG_LOGLEVEL_LOG4J_DEBUG
},
73 { .name
= "LOG4J_DEBUG", .value
= LTTNG_LOGLEVEL_LOG4J_DEBUG
},
74 { .name
= "TRACE", .value
= LTTNG_LOGLEVEL_LOG4J_TRACE
},
75 { .name
= "LOG4J_TRACE", .value
= LTTNG_LOGLEVEL_LOG4J_TRACE
},
76 { .name
= "ALL", .value
= LTTNG_LOGLEVEL_LOG4J_ALL
},
77 { .name
= "LOG4J_ALL", .value
= LTTNG_LOGLEVEL_LOG4J_ALL
},
81 const struct loglevel_name_value loglevel_jul_values
[] = {
82 { .name
= "OFF", .value
= LTTNG_LOGLEVEL_JUL_OFF
},
83 { .name
= "JUL_OFF", .value
= LTTNG_LOGLEVEL_JUL_OFF
},
84 { .name
= "SEVERE", .value
= LTTNG_LOGLEVEL_JUL_SEVERE
},
85 { .name
= "JUL_SEVERE", .value
= LTTNG_LOGLEVEL_JUL_SEVERE
},
86 { .name
= "WARNING", .value
= LTTNG_LOGLEVEL_JUL_WARNING
},
87 { .name
= "JUL_WARNING", .value
= LTTNG_LOGLEVEL_JUL_WARNING
},
88 { .name
= "INFO", .value
= LTTNG_LOGLEVEL_JUL_INFO
},
89 { .name
= "JUL_INFO", .value
= LTTNG_LOGLEVEL_JUL_INFO
},
90 { .name
= "CONFIG", .value
= LTTNG_LOGLEVEL_JUL_CONFIG
},
91 { .name
= "JUL_CONFIG", .value
= LTTNG_LOGLEVEL_JUL_CONFIG
},
92 { .name
= "FINE", .value
= LTTNG_LOGLEVEL_JUL_FINE
},
93 { .name
= "JUL_FINE", .value
= LTTNG_LOGLEVEL_JUL_FINE
},
94 { .name
= "FINER", .value
= LTTNG_LOGLEVEL_JUL_FINER
},
95 { .name
= "JUL_FINER", .value
= LTTNG_LOGLEVEL_JUL_FINER
},
96 { .name
= "FINEST", .value
= LTTNG_LOGLEVEL_JUL_FINEST
},
97 { .name
= "JUL_FINEST", .value
= LTTNG_LOGLEVEL_JUL_FINEST
},
98 { .name
= "ALL", .value
= LTTNG_LOGLEVEL_JUL_ALL
},
99 { .name
= "JUL_ALL", .value
= LTTNG_LOGLEVEL_JUL_ALL
},
103 const struct loglevel_name_value loglevel_python_values
[] = {
104 { .name
= "CRITICAL", .value
= LTTNG_LOGLEVEL_PYTHON_CRITICAL
},
105 { .name
= "PYTHON_CRITICAL", .value
= LTTNG_LOGLEVEL_PYTHON_CRITICAL
},
106 { .name
= "ERROR", .value
= LTTNG_LOGLEVEL_PYTHON_ERROR
},
107 { .name
= "PYTHON_ERROR", .value
= LTTNG_LOGLEVEL_PYTHON_ERROR
},
108 { .name
= "WARNING", .value
= LTTNG_LOGLEVEL_PYTHON_WARNING
},
109 { .name
= "PYTHON_WARNING", .value
= LTTNG_LOGLEVEL_PYTHON_WARNING
},
110 { .name
= "INFO", .value
= LTTNG_LOGLEVEL_PYTHON_INFO
},
111 { .name
= "PYTHON_INFO", .value
= LTTNG_LOGLEVEL_PYTHON_INFO
},
112 { .name
= "DEBUG", .value
= LTTNG_LOGLEVEL_PYTHON_DEBUG
},
113 { .name
= "PYTNON_DEBUG", .value
= LTTNG_LOGLEVEL_PYTHON_DEBUG
},
114 { .name
= "NOTSET", .value
= LTTNG_LOGLEVEL_PYTHON_NOTSET
},
115 { .name
= "PYTHON_NOTSET", .value
= LTTNG_LOGLEVEL_PYTHON_NOTSET
},
119 bool string_equal_insensitive(const char *a
, const char *b
)
121 return strcasecmp(a
, b
) == 0;
125 int lookup_value_from_name(const struct loglevel_name_value values
[],
126 size_t values_count
, const char *name
)
135 for (i
= 0; i
< values_count
; i
++) {
136 if (string_equal_insensitive(values
[i
].name
, name
)) {
138 ret
= values
[i
].value
;
147 static bool loglevel_parse_range_string_common(const char *str
,
148 const struct loglevel_name_value
*nvs
,
155 const struct loglevel_name_value
*nv
;
157 for (i
= 0; i
< nvs_count
; i
++) {
160 if (strncmp(str
, nv
->name
, strlen(nv
->name
)) == 0) {
165 if (i
== nvs_count
) {
170 str
+= strlen(nv
->name
);
178 if (strncmp(str
, "..", strlen("..")) != 0) {
185 *max
= LTTNG_LOGLEVEL_EMERG
;
190 for (i
= 0; i
< nvs_count
; i
++) {
193 if (strcmp(str
, nv
->name
) == 0) {
198 if (i
== nvs_count
) {
215 int loglevel_name_to_value(const char *name
, enum lttng_loglevel
*loglevel
)
217 int ret
= lookup_value_from_name(loglevel_values
,
218 ARRAY_SIZE(loglevel_values
), name
);
221 *loglevel
= (typeof(*loglevel
)) ret
;
229 bool loglevel_parse_range_string(const char *str
,
230 enum lttng_loglevel
*min
,
231 enum lttng_loglevel
*max
)
233 int min_int
, max_int
;
234 bool ret
= loglevel_parse_range_string_common(str
, loglevel_values
,
235 ARRAY_SIZE(loglevel_values
), &min_int
, &max_int
);
244 int loglevel_log4j_name_to_value(
245 const char *name
, enum lttng_loglevel_log4j
*loglevel
)
247 int ret
= lookup_value_from_name(loglevel_log4j_values
,
248 ARRAY_SIZE(loglevel_log4j_values
),
252 *loglevel
= (typeof(*loglevel
)) ret
;
260 bool loglevel_log4j_parse_range_string(const char *str
,
261 enum lttng_loglevel_log4j
*min
,
262 enum lttng_loglevel_log4j
*max
)
264 int min_int
, max_int
;
265 bool ret
= loglevel_parse_range_string_common(str
,
266 loglevel_log4j_values
,
267 ARRAY_SIZE(loglevel_log4j_values
), &min_int
, &max_int
);
276 int loglevel_jul_name_to_value(
277 const char *name
, enum lttng_loglevel_jul
*loglevel
)
279 int ret
= lookup_value_from_name(loglevel_jul_values
,
280 ARRAY_SIZE(loglevel_jul_values
),
284 *loglevel
= (typeof(*loglevel
)) ret
;
292 bool loglevel_jul_parse_range_string(const char *str
,
293 enum lttng_loglevel_jul
*min
,
294 enum lttng_loglevel_jul
*max
)
296 int min_int
, max_int
;
297 bool ret
= loglevel_parse_range_string_common(str
, loglevel_jul_values
,
298 ARRAY_SIZE(loglevel_jul_values
), &min_int
, &max_int
);
307 int loglevel_python_name_to_value(
308 const char *name
, enum lttng_loglevel_python
*loglevel
)
310 int ret
= lookup_value_from_name(loglevel_python_values
,
311 ARRAY_SIZE(loglevel_python_values
),
315 *loglevel
= (typeof(*loglevel
)) ret
;
323 bool loglevel_python_parse_range_string(const char *str
,
324 enum lttng_loglevel_python
*min
,
325 enum lttng_loglevel_python
*max
)
327 int min_int
, max_int
;
328 bool ret
= loglevel_parse_range_string_common(str
,
329 loglevel_python_values
,
330 ARRAY_SIZE(loglevel_python_values
), &min_int
, &max_int
);
339 const char *lookup_name_from_value(const struct loglevel_name_value values
[],
340 size_t values_count
, int loglevel
)
343 const char *name
= NULL
;
345 for (i
= 0; i
< values_count
; i
++) {
346 if (values
[i
].value
== loglevel
) {
348 name
= values
[i
].name
;
358 const char *loglevel_value_to_name(int loglevel
)
360 return lookup_name_from_value(
361 loglevel_values
, ARRAY_SIZE(loglevel_values
), loglevel
);
365 const char *loglevel_log4j_value_to_name(int loglevel
)
367 return lookup_name_from_value(loglevel_log4j_values
,
368 ARRAY_SIZE(loglevel_log4j_values
), loglevel
);
372 const char *loglevel_jul_value_to_name(int loglevel
)
374 return lookup_name_from_value(loglevel_jul_values
,
375 ARRAY_SIZE(loglevel_jul_values
), loglevel
);
379 const char *loglevel_python_value_to_name(int loglevel
)
381 return lookup_name_from_value(loglevel_python_values
,
382 ARRAY_SIZE(loglevel_python_values
), loglevel
);