Debian Codegraph @

include/log.h

raw symbols SCIP
1 /*
2 * AIDE (Advanced Intrusion Detection Environment)
3 *
4 * Copyright (C) 2020, 2022, 2023, 2025 Hannes von Haugwitz
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #ifndef _LOG_H_INCLUDED
22 #define _LOG_H_INCLUDED
23
24 #include <stdbool.h>
25
26 /* log levels */
27 typedef enum { /* preserve order */
28 LOG_LEVEL_UNSET = 0,
29 LOG_LEVEL_ERROR = 1,
30 LOG_LEVEL_WARNING = 2,
31 LOG_LEVEL_NOTICE = 3,
32 LOG_LEVEL_INFO = 4,
33 LOG_LEVEL_COMPARE = 5,
34 LOG_LEVEL_RULE = 6,
35 LOG_LEVEL_CONFIG = 7,
36 LOG_LEVEL_DEBUG = 8,
37 LOG_LEVEL_LIMIT = 9,
38 LOG_LEVEL_THREAD = 10,
39 LOG_LEVEL_TRACE = 11,
40 } LOG_LEVEL;
41
42 bool is_log_level_unset(void);
43
44 void set_log_level(LOG_LEVEL);
45 void set_colored_log(bool);
46
47 const char * get_log_level_name(LOG_LEVEL);
48
49 LOG_LEVEL get_log_level_from_string(char*);
50
51 LOG_LEVEL toogle_log_level(LOG_LEVEL);
52
53 void log_msg(LOG_LEVEL, const char* ,...)
54 #ifdef __GNUC__
55 __attribute__ ((format (printf, 2, 3)))
56 #endif
57 ;
58
59 #define LOG_CONFIG_FORMAT_LINE(log_level, format, ...) \
60 if (linebuf) { \
61 log_msg(log_level,"%s:%d: " format " (line: '%s')", filename, linenumber, __VA_ARGS__, linebuf); \
62 } else { \
63 log_msg(log_level,"%s: " format, filename, __VA_ARGS__); \
64 }
65
66 #define LOG_CONFIG_FORMAT_LINE_PREFIX(log_level, format, ...) \
67 if (rule_prefix) { \
68 log_msg(log_level,"%s:%d: " format " (line: '%s', prefix: '%s')", filename, linenumber, __VA_ARGS__, linebuf, rule_prefix); \
69 } else { \
70 log_msg(log_level,"%s:%d: " format " (line: '%s')", filename, linenumber, __VA_ARGS__, linebuf); \
71 }
72
73 #define LOG_WHOAMI(log_level, format, ...) log_msg(log_level, "%*s%s" format, whoami?10:0, whoami?whoami:"", whoami?": ":"", __VA_ARGS__);
74
75 #endif