87 return "\033[" + std::to_string(
static_cast<int>(code)) +
"m";
111 const auto now = std::chrono::system_clock::now();
112 const std::time_t seconds = std::chrono::system_clock::to_time_t(now);
114 = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count()
119 localtime_s(&local, &seconds);
121 localtime_r(&seconds, &local);
124 std::array<char, 16> clock {};
125 std::strftime(clock.data(), clock.size(),
"%H:%M:%S", &local);
126 return std::format(
"{}.{:03}", clock.data(), millis);
137 int emLevel = EM_LOG_CONSOLE;
140 emLevel = EM_LOG_CONSOLE;
143 emLevel = EM_LOG_CONSOLE;
146 emLevel = EM_LOG_WARN;
149 emLevel = EM_LOG_ERROR;
167 *
output << color << message << reset <<
"\n";
203 constexpr int bar_width = 20;
204 const int filled =
static_cast<int>(
progress *
static_cast<float>(bar_width));
208 bar.reserve(bar_width * 3);
209 for (
int i = 0; i < bar_width; ++i) {
210 bar += (i < filled) ?
"█" :
"░";
213 const std::string progress_message
214 = std::format(
"[{}] {:>3}% {}", bar,
static_cast<int>(
progress * 100.0f), message);
Structured logging system.
const char * level_to_string(asw::log::Level level)
AnsiCode level_to_ansi(asw::log::Level level)
AnsiCode
ANSI escape codes for terminal formatting.
asw::log::Level current_level
std::string get_timestamp()
std::string ansi_to_string(AnsiCode code)
void set_output(std::ostream &stream)
Set the output stream (default: std::cerr).
void info(const std::string &message)
Log an info message.
void debug(const std::string &message)
Log a debug message.
void log_message(Level level, const std::string &message)
Log a message at the specified level. Messages below the current log level are ignored.
void error(const std::string &message)
Log an error message.
void warn(const std::string &message)
Log a warning message.
Level
Log severity levels.
void progress(float progress, std::string message)
Log a progress message with a percentage.
void set_level(Level level)
Set the minimum log level (messages below this are ignored).