#include "./log.hpp"
#if SUBSAT_LOGGING_ENABLED
#include <unistd.h>
#include <utility>
static LogLevel
get_max_log_level(subsat::string const& fn, subsat::string const& pretty_fn)
{
(void)fn;
(void)pretty_fn;
return LogLevel::Trace;
}
bool
subsat_should_log(LogLevel msg_level, subsat::string fn, subsat::string pretty_fn)
{
LogLevel max_log_level = get_max_log_level(fn, pretty_fn);
return msg_level <= max_log_level;
}
static char const*
level_name(LogLevel msg_level)
{
switch (msg_level) {
case LogLevel::Error: return "[ERROR]";
case LogLevel::Warn: return "[WARN] ";
case LogLevel::Info: return "[INFO] ";
case LogLevel::Debug: return "[DEBUG]";
case LogLevel::Trace: return "[TRACE]";
default: return "[???] ";
}
}
static char const*
level_color(LogLevel msg_level)
{
switch (msg_level) {
case LogLevel::Error:
return "\x1B[31m"; case LogLevel::Warn:
return "\x1B[33m"; case LogLevel::Info:
return "\x1B[34m"; default:
return nullptr;
}
}
std::pair<std::ostream&, bool>
subsat_log(LogLevel msg_level, subsat::string fn, subsat::string )
{
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 << level_name(msg_level) << " [" << fn << "] " << subsat::string(padding, ' ');
return {os, (bool)color};
}
#endif