logger: Add default logging level 'notice'

Between info and warning. Should be for things the user should be aware
of but not imply anything has to be done about it.
This commit is contained in:
patrick96 2020-04-22 00:12:08 +02:00 committed by Patrick Ziegler
parent ecbe77bbda
commit cae3848030
6 changed files with 21 additions and 5 deletions

View File

@ -42,6 +42,7 @@ _polybar() {
local log_levels='error
warning
notice
info
trace'

View File

@ -17,7 +17,7 @@ _polybar() {
_arguments -n : \
'(-)'{-h,--help}'[Display help text and exit]' \
'(-)'{-v,--version}'[Display build details and exit]' \
"($L $Q)"{-l,--log=}'[Set the logging verbosity (default: warning)]:verbosity level:(error warning info trace)' \
"($L $Q)"{-l,--log=}'[Set the logging verbosity (default: notice)]:verbosity level:(error warning notice info trace)' \
"($L $Q)"{-q,--quiet}'[Be quiet (will override -l)]' \
"($C)"{-c,--config=}'[Path to the configuration file]:configuration file:_files' \
"($R)"{-r,--reload}'[Reload when the configuration has been modified]' \

View File

@ -23,8 +23,8 @@ OPTIONS
Display build details and exit
.. option:: -l, --log=LEVEL
| Set the logging verbosity (default: **WARNING**)
| *LEVEL* is one of: error, warning, info, trace
| Set the logging verbosity (default: **notice**)
| *LEVEL* is one of: error, warning, notice, info, trace
.. option:: -q, --quiet
Be quiet (will override -l)

View File

@ -22,6 +22,7 @@ enum class loglevel {
NONE = 0,
ERROR,
WARNING,
NOTICE,
INFO,
TRACE,
};
@ -66,6 +67,14 @@ class logger {
output(loglevel::INFO, message, std::forward<Args>(args)...);
}
/**
* Output a notice
*/
template <typename... Args>
void notice(const string& message, Args&&... args) const {
output(loglevel::NOTICE, message, std::forward<Args>(args)...);
}
/**
* Output a warning message
*/

View File

@ -38,19 +38,23 @@ logger::logger(loglevel level) : m_level(level) {
if (isatty(m_fd)) {
m_prefixes[loglevel::TRACE] = "\r\033[0;32m- \033[0m";
m_prefixes[loglevel::INFO] = "\r\033[1;32m* \033[0m";
m_prefixes[loglevel::NOTICE] = "\r\033[1;34mnotice: \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::NOTICE] = "\033[0m";
m_suffixes[loglevel::WARNING] = "\033[0m";
m_suffixes[loglevel::ERROR] = "\033[0m";
} else {
m_prefixes.emplace(make_pair(loglevel::TRACE, "polybar|trace: "));
m_prefixes.emplace(make_pair(loglevel::INFO, "polybar|info: "));
m_prefixes.emplace(make_pair(loglevel::NOTICE, "polybar|notice: "));
m_prefixes.emplace(make_pair(loglevel::WARNING, "polybar|warn: "));
m_prefixes.emplace(make_pair(loglevel::ERROR, "polybar|error: "));
m_suffixes.emplace(make_pair(loglevel::TRACE, ""));
m_suffixes.emplace(make_pair(loglevel::INFO, ""));
m_suffixes.emplace(make_pair(loglevel::NOTICE, ""));
m_suffixes.emplace(make_pair(loglevel::WARNING, ""));
m_suffixes.emplace(make_pair(loglevel::ERROR, ""));
}
@ -77,6 +81,8 @@ loglevel logger::parse_verbosity(const string& name, loglevel fallback) {
return loglevel::ERROR;
} else if (string_util::compare(name, "warning")) {
return loglevel::WARNING;
} else if (string_util::compare(name, "notice")) {
return loglevel::NOTICE;
} else if (string_util::compare(name, "info")) {
return loglevel::INFO;
} else if (string_util::compare(name, "trace")) {

View File

@ -16,7 +16,7 @@ int main(int argc, char** argv) {
const command_line::options opts{
command_line::option{"-h", "--help", "Display this help and exit"},
command_line::option{"-v", "--version", "Display build details and exit"},
command_line::option{"-l", "--log", "Set the logging verbosity (default: WARNING)", "LEVEL", {"error", "warning", "info", "trace"}},
command_line::option{"-l", "--log", "Set the logging verbosity (default: notice)", "LEVEL", {"error", "warning", "notice", "info", "trace"}},
command_line::option{"-q", "--quiet", "Be quiet (will override -l)"},
command_line::option{"-c", "--config", "Path to the configuration file", "FILE"},
command_line::option{"-r", "--reload", "Reload when the configuration has been modified"},
@ -32,7 +32,7 @@ int main(int argc, char** argv) {
unsigned char exit_code{EXIT_SUCCESS};
bool reload{false};
logger& logger{const_cast<decltype(logger)>(logger::make(loglevel::WARNING))};
logger& logger{const_cast<decltype(logger)>(logger::make(loglevel::NOTICE))};
try {
//==================================================