3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-29 20:05:51 +00:00

Add more logging to polysat (#5186)

* Add polysat logging support

* Don't really need the usual log levels

* Indent log headings

* Add display method to ptr_vector

* Add some logging to solver

* Use __FUNCSIG__ on MSVC
This commit is contained in:
Jakob Rath 2021-04-15 17:35:57 +02:00 committed by GitHub
parent 7067fc16ae
commit feb31045f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 271 additions and 3 deletions

92
src/math/polysat/log.cpp Normal file
View file

@ -0,0 +1,92 @@
#include <unistd.h>
#include <utility>
#include "math/polysat/log.h"
#if POLYSAT_LOGGING_ENABLED
static LogLevel
get_max_log_level(std::string const& fn, std::string const& pretty_fn)
{
(void)fn;
(void)pretty_fn;
// bool const from_decision_queue = pretty_fn.find("DecisionQueue") != std::string::npos;
// if (from_decision_queue) {
// return LogLevel::Info;
// }
// if (pretty_fn.find("add_") != std::string::npos) {
// return LogLevel::Info;
// }
// if (fn == "analyze") {
// return LogLevel::Trace;
// }
// if (fn.find("minimize") != std::string::npos) {
// return LogLevel::Trace;
// }
// if (fn == "propagate_literal") {
// return LogLevel::Trace;
// }
return LogLevel::Verbose;
// return LogLevel::Warn;
}
/// Filter log messages
bool
polysat_should_log(LogLevel msg_level, std::string fn, std::string pretty_fn)
{
LogLevel max_log_level = get_max_log_level(fn, pretty_fn);
return msg_level <= max_log_level;
}
static char const*
level_color(LogLevel msg_level)
{
switch (msg_level) {
case LogLevel::Heading1:
return "\x1B[31m"; // red
case LogLevel::Heading2:
return "\x1B[33m"; // yellow
case LogLevel::Heading3:
return "\x1B[34m"; // blue
default:
return nullptr;
}
}
int polysat_log_indent_level = 0;
std::pair<std::ostream&, bool>
polysat_log(LogLevel msg_level, std::string fn, std::string /* pretty_fn */)
{
std::ostream& os = std::cerr;
int const fd = fileno(stderr);
size_t width = 20;
size_t padding = width - std::min(width, fn.size());
char const* color = level_color(msg_level);
if (color && !isatty(fd)) { color = nullptr; }
if (color) { os << color; }
os << "[" << fn << "] " << std::string(padding, ' ');
os << std::string(polysat_log_indent_level, ' ');
return {os, (bool)color};
}
polysat_log_indent::polysat_log_indent(int amount)
: m_amount{amount}
{
polysat_log_indent_level += m_amount;
}
polysat_log_indent::~polysat_log_indent()
{
polysat_log_indent_level -= m_amount;
}
#endif // POLYSAT_LOGGING_ENABLED