Debian Codegraph @

src/io/log.h

raw symbols SCIP
1
2 /**
3 *
4 * @file log.h
5 *
6 * Part of the OpenJazz project
7 *
8 * @par Licence:
9 * Copyright (c) 2015-2026 Carsten Teibes
10 *
11 * OpenJazz is distributed under the terms of
12 * the GNU General Public License, version 2.0
13 *
14 */
15
16 #ifndef OJ_LOG_H
17 #define OJ_LOG_H
18
19 #include "OpenJazz.h"
20 #include <cstdio>
21
22 // Loglevels
23 enum {
24 LL_MAX,
25 LL_TRACE,
26 LL_DEBUG,
27 LL_INFO,
28 LL_WARN,
29 LL_ERROR,
30 LL_FATAL
31 };
32
33 /* Let the compiler help with parameter formats
34 * (arguments are shifted by 1, because of hidden "this" pointer)
35 */
36 #ifdef __GNUG__
37 #define LIKE_PRINTF __attribute__((format(printf, 5, 6)))
38 #else
39 #define LIKE_PRINTF
40 #endif
41
42 // Class
43
44 /// Configuration
45 class Log {
46
47 public:
48 Log();
49 ~Log();
50
51 void setLevel(int level);
52 int getLevel();
53 void setQuiet(bool enable);
54 void log(int level, const char *file, int line, const char *fmt, ...) LIKE_PRINTF;
55
56 private:
57 Log(const Log&); // non construction-copyable
58 Log& operator=(const Log&); // non copyable
59
60 FILE *logfile;
61 int level;
62 bool quiet;
63 bool color_stdout, color_stderr;
64
65 };
66
67 // Variable
68
69 EXTERN Log logger;
70
71 // Helper macros
72
73 #define LOG_MAX(...) logger.log(LL_MAX, __FILE__, __LINE__, __VA_ARGS__)
74 #define LOG_TRACE(...) logger.log(LL_TRACE, __FILE__, __LINE__, __VA_ARGS__)
75 #define LOG_DEBUG(...) logger.log(LL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
76 #define LOG_INFO(...) logger.log(LL_INFO, __FILE__, __LINE__, __VA_ARGS__)
77 #define LOG_WARN(...) logger.log(LL_WARN, __FILE__, __LINE__, __VA_ARGS__)
78 #define LOG_ERROR(...) logger.log(LL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
79 #define LOG_FATAL(...) logger.log(LL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
80
81 #undef LIKE_PRINTF
82
83 #endif