mirror of
https://github.com/Z3Prover/z3
synced 2025-07-19 10:52:02 +00:00
Allow disabling log messages
This commit is contained in:
parent
1d805807e9
commit
05ddac5ddc
2 changed files with 28 additions and 11 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#undef min
|
#undef min
|
||||||
#endif
|
#endif
|
||||||
|
#include <atomic>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "util/util.h"
|
#include "util/util.h"
|
||||||
|
@ -25,6 +26,12 @@ Other:
|
||||||
|
|
||||||
#if POLYSAT_LOGGING_ENABLED
|
#if POLYSAT_LOGGING_ENABLED
|
||||||
|
|
||||||
|
std::atomic<bool> g_log_enabled(true);
|
||||||
|
|
||||||
|
void set_log_enabled(bool log_enabled) {
|
||||||
|
g_log_enabled = log_enabled;
|
||||||
|
}
|
||||||
|
|
||||||
static LogLevel get_max_log_level(std::string const& fn, std::string const& pretty_fn) {
|
static LogLevel get_max_log_level(std::string const& fn, std::string const& pretty_fn) {
|
||||||
(void)fn;
|
(void)fn;
|
||||||
(void)pretty_fn;
|
(void)pretty_fn;
|
||||||
|
@ -45,20 +52,23 @@ static LogLevel get_max_log_level(std::string const& fn, std::string const& pret
|
||||||
|
|
||||||
/// Filter log messages
|
/// Filter log messages
|
||||||
bool polysat_should_log(LogLevel msg_level, std::string fn, std::string pretty_fn) {
|
bool polysat_should_log(LogLevel msg_level, std::string fn, std::string pretty_fn) {
|
||||||
|
if (!g_log_enabled)
|
||||||
|
return false;
|
||||||
LogLevel max_log_level = get_max_log_level(fn, pretty_fn);
|
LogLevel max_log_level = get_max_log_level(fn, pretty_fn);
|
||||||
return msg_level <= max_log_level;
|
return msg_level <= max_log_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const* color_red() { return "\x1B[31m"; }
|
||||||
|
char const* color_yellow() { return "\x1B[33m"; }
|
||||||
|
char const* color_blue() { return "\x1B[34m"; }
|
||||||
|
char const* color_reset() { return "\x1B[0m"; }
|
||||||
|
|
||||||
static char const* level_color(LogLevel msg_level) {
|
static char const* level_color(LogLevel msg_level) {
|
||||||
switch (msg_level) {
|
switch (msg_level) {
|
||||||
case LogLevel::Heading1:
|
case LogLevel::Heading1: return color_red();
|
||||||
return "[31m"; // red
|
case LogLevel::Heading2: return color_yellow();
|
||||||
case LogLevel::Heading2:
|
case LogLevel::Heading3: return color_blue();
|
||||||
return "[33m"; // yellow
|
default: return nullptr;
|
||||||
case LogLevel::Heading3:
|
|
||||||
return "[34m"; // blue
|
|
||||||
default:
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,15 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
char const* color_blue();
|
||||||
|
char const* color_yellow();
|
||||||
|
char const* color_red();
|
||||||
|
char const* color_reset();
|
||||||
|
|
||||||
|
|
||||||
#if POLYSAT_LOGGING_ENABLED
|
#if POLYSAT_LOGGING_ENABLED
|
||||||
|
|
||||||
|
void set_log_enabled(bool log_enabled);
|
||||||
|
|
||||||
class polysat_log_indent
|
class polysat_log_indent
|
||||||
{
|
{
|
||||||
|
@ -57,9 +64,8 @@ polysat_log(LogLevel msg_level, std::string fn, std::string pretty_fn);
|
||||||
std::ostream& os = pair.first; \
|
std::ostream& os = pair.first; \
|
||||||
bool should_reset = pair.second; \
|
bool should_reset = pair.second; \
|
||||||
os << x; \
|
os << x; \
|
||||||
if (should_reset) { \
|
if (should_reset) \
|
||||||
os << "\x1B[0m"; /* reset color */ \
|
os << color_reset(); \
|
||||||
} \
|
|
||||||
os << std::endl; \
|
os << std::endl; \
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
@ -87,6 +93,7 @@ polysat_log(LogLevel msg_level, std::string fn, std::string pretty_fn);
|
||||||
|
|
||||||
#else // POLYSAT_LOGGING_ENABLED
|
#else // POLYSAT_LOGGING_ENABLED
|
||||||
|
|
||||||
|
void set_log_enabled(bool) {}
|
||||||
|
|
||||||
#define LOG_(lvl, x) \
|
#define LOG_(lvl, x) \
|
||||||
do { \
|
do { \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue