Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
Logger.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <atomic>
9#include <memory>
10#include <vector>
11
12// Color definitions for console output
13#define BLUE "\033[34m"
14#define BOLD "\033[1m"
15#define CYAN "\033[36m"
16#define GREEN "\033[32m"
17#define MAGENTA "\033[35m"
18#define RED "\033[31m"
19#define RESET "\033[0m"
20#define WHITE "\033[37m"
21#define YELLOW "\033[33m"
22#define FUNC_STYLE "\033[2m"
23#define ERROR_STYLE "\033[1m"
24
25// Function name macro (compiler-specific)
26#if defined(__GNUC__)
27#ifdef __cplusplus
28#define FUNCTION_NAME ((__PRETTY_FUNCTION__) ? __PRETTY_FUNCTION__ : "UnknownFunction")
29#else
30#define FUNCTION_NAME ((__FUNCTION__) ? __FUNCTION__ : "UnknownFunction")
31#endif
32#else
33#define FUNCTION_NAME "UnknownFunction"
34#endif
35
40void
42
50void
51log(int verbosityLevel, const char* color, const char* fmt...);
52
61void
62logDebug(int verbosityLevel, const char* color, const char* issuer, const char* fmt...);
63
73void
74logClause(int verbosityLevel, const char* color, const int* lits, unsigned int size, const char* fmt...);
75
80void
81logSolution(const char* string);
82
86void
88
92void
94
99void
100logModel(const std::vector<int>& model);
101
105extern std::atomic<bool> quiet;
106
107// Logging macros for different verbosity levels and purposes
108
112#define LOG(level, ...) \
113 do { \
114 log(level, RESET, __VA_ARGS__); \
115 } while (0)
116
120#define LOGERROR(...) \
121 do { \
122 logDebug(0, RED, FUNCTION_NAME, __VA_ARGS__); \
123 } while (0)
124
128#define PABORT(EXIT_CODE, ...) \
129 do { \
130 logDebug(0, RED, FUNCTION_NAME, __VA_ARGS__); \
131 exit(EXIT_CODE); \
132 } while (0)
133
137#define LOGWARN(...) \
138 do { \
139 logDebug(0, YELLOW, FUNCTION_NAME, __VA_ARGS__); \
140 } while (0)
141
145#define LOGSTAT(...) \
146 do { \
147 log(0, GREEN, __VA_ARGS__); \
148 } while (0)
149
150#ifndef PQUIET
154#define LOG0(...) \
155 do { \
156 log(0, RESET, __VA_ARGS__); \
157 } while (0)
158
162#define LOG1(...) \
163 do { \
164 log(1, RESET, __VA_ARGS__); \
165 } while (0)
166
170#define LOG2(...) \
171 do { \
172 log(2, RESET, __VA_ARGS__); \
173 } while (0)
174
178#define LOG3(...) \
179 do { \
180 log(3, RESET, __VA_ARGS__); \
181 } while (0)
182
186#define LOG4(...) \
187 do { \
188 log(4, RESET, __VA_ARGS__); \
189 } while (0)
190
194#define LOGVECTOR(lits, size, ...) \
195 do { \
196 logClause(1, CYAN, lits, size, __VA_ARGS__); \
197 } while (0)
198
199#else
200// Define empty macros when PQUIET is defined
201#define LOG0(...)
202#define LOG1(...)
203#define LOG2(...)
204#define LOG3(...)
205#define LOG4(...)
206#define LOGVECTOR(...)
207#endif
208
209#ifndef NDEBUG
213#define LOGDEBUG1(...) \
214 do { \
215 logDebug(1, BLUE, FUNCTION_NAME, __VA_ARGS__); \
216 } while (0)
217
221#define LOGDEBUG2(...) \
222 do { \
223 logDebug(2, MAGENTA, FUNCTION_NAME, __VA_ARGS__); \
224 } while (0)
225
229#define LOGDEBUG3(...) \
230 do { \
231 logDebug(4, MAGENTA, FUNCTION_NAME, __VA_ARGS__); \
232 } while (0)
233
237#define LOGCLAUSE1(lits, size, ...) \
238 do { \
239 logClause(2, CYAN, lits, size, __VA_ARGS__); \
240 } while (0)
241
245#define LOGCLAUSE2(lits, size, ...) \
246 do { \
247 logClause(5, CYAN, lits, size, __VA_ARGS__); \
248 } while (0)
249
250#else
251// Define empty macros when NDEBUG is defined
252#define LOGDEBUG1(...)
253#define LOGDEBUG2(...)
254#define LOGDEBUG3(...)
255#define LOGCLAUSE1(...)
256#define LOGCLAUSE2(...)
257#endif
void setVerbosityLevel(int level)
Set the verbosity level for logging.
std::atomic< bool > quiet
Global flag to enable/disable logging.
void log(int verbosityLevel, const char *color, const char *fmt...)
Log a message with a specified verbosity level and color.
void logModel(const std::vector< int > &model)
Log the model (satisfying assignment) found by the SAT solver.
void logDebug(int verbosityLevel, const char *color, const char *issuer, const char *fmt...)
Log a debug message with a specified verbosity level, color, and issuer.
void unlockLogger()
Release the logger mutex after logging.
void logClause(int verbosityLevel, const char *color, const int *lits, unsigned int size, const char *fmt...)
Log a clause with a specified verbosity level and color.
void lockLogger()
Acquire the logger mutex to ensure thread-safe logging.
void logSolution(const char *string)
Log the solution status of the SAT solver.