polybar-dwm/src/components/logger.cpp

61 lines
1.5 KiB
C++
Raw Normal View History

2016-11-20 22:04:31 +00:00
#include <unistd.h>
2016-11-02 19:22:45 +00:00
#include "components/logger.hpp"
#include "utils/string.hpp"
2016-11-19 05:22:44 +00:00
POLYBAR_NS
2016-11-02 19:22:45 +00:00
/**
* Construct logger
*/
logger::logger(loglevel level) : m_level(level) {
if (isatty(m_fd)) {
// clang-format off
m_prefixes[loglevel::TRACE] = "\r\033[0;90m- ";
m_prefixes[loglevel::INFO] = "\r\033[1;32m* \033[0m";
m_prefixes[loglevel::WARNING] = "\r\033[1;33mwarn: \033[0m";
m_prefixes[loglevel::ERROR] = "\r\033[1;31merror: \033[0m";
m_suffixes[loglevel::TRACE] = "\033[0m";
m_suffixes[loglevel::INFO] = "\033[0m";
m_suffixes[loglevel::WARNING] = "\033[0m";
m_suffixes[loglevel::ERROR] = "\033[0m";
// clang-format on
}
}
/**
* Set output verbosity
*/
void logger::verbosity(loglevel level) {
#ifndef DEBUG
if (level == loglevel::TRACE)
throw application_error("not a debug build: trace disabled...");
#endif
m_level = level;
}
/**
* Set output verbosity by loglevel name
*/
void logger::verbosity(string level) {
verbosity(parse_loglevel_name(level));
}
/**
* Convert given loglevel name to its enum type counterpart
*/
loglevel parse_loglevel_name(string name) {
if (string_util::compare(name, "error"))
return loglevel::ERROR;
else if (string_util::compare(name, "warning"))
return loglevel::WARNING;
else if (string_util::compare(name, "info"))
return loglevel::INFO;
else if (string_util::compare(name, "trace"))
return loglevel::TRACE;
else
return loglevel::NONE;
2016-11-03 17:19:47 +00:00
}
2016-11-02 19:22:45 +00:00
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END