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:
parent
ecbe77bbda
commit
cae3848030
@ -42,6 +42,7 @@ _polybar() {
|
|||||||
|
|
||||||
local log_levels='error
|
local log_levels='error
|
||||||
warning
|
warning
|
||||||
|
notice
|
||||||
info
|
info
|
||||||
trace'
|
trace'
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ _polybar() {
|
|||||||
_arguments -n : \
|
_arguments -n : \
|
||||||
'(-)'{-h,--help}'[Display help text and exit]' \
|
'(-)'{-h,--help}'[Display help text and exit]' \
|
||||||
'(-)'{-v,--version}'[Display build details 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)]' \
|
"($L $Q)"{-q,--quiet}'[Be quiet (will override -l)]' \
|
||||||
"($C)"{-c,--config=}'[Path to the configuration file]:configuration file:_files' \
|
"($C)"{-c,--config=}'[Path to the configuration file]:configuration file:_files' \
|
||||||
"($R)"{-r,--reload}'[Reload when the configuration has been modified]' \
|
"($R)"{-r,--reload}'[Reload when the configuration has been modified]' \
|
||||||
|
@ -23,8 +23,8 @@ OPTIONS
|
|||||||
Display build details and exit
|
Display build details and exit
|
||||||
.. option:: -l, --log=LEVEL
|
.. option:: -l, --log=LEVEL
|
||||||
|
|
||||||
| Set the logging verbosity (default: **WARNING**)
|
| Set the logging verbosity (default: **notice**)
|
||||||
| *LEVEL* is one of: error, warning, info, trace
|
| *LEVEL* is one of: error, warning, notice, info, trace
|
||||||
.. option:: -q, --quiet
|
.. option:: -q, --quiet
|
||||||
|
|
||||||
Be quiet (will override -l)
|
Be quiet (will override -l)
|
||||||
|
@ -22,6 +22,7 @@ enum class loglevel {
|
|||||||
NONE = 0,
|
NONE = 0,
|
||||||
ERROR,
|
ERROR,
|
||||||
WARNING,
|
WARNING,
|
||||||
|
NOTICE,
|
||||||
INFO,
|
INFO,
|
||||||
TRACE,
|
TRACE,
|
||||||
};
|
};
|
||||||
@ -66,6 +67,14 @@ class logger {
|
|||||||
output(loglevel::INFO, message, std::forward<Args>(args)...);
|
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
|
* Output a warning message
|
||||||
*/
|
*/
|
||||||
|
@ -38,19 +38,23 @@ logger::logger(loglevel level) : m_level(level) {
|
|||||||
if (isatty(m_fd)) {
|
if (isatty(m_fd)) {
|
||||||
m_prefixes[loglevel::TRACE] = "\r\033[0;32m- \033[0m";
|
m_prefixes[loglevel::TRACE] = "\r\033[0;32m- \033[0m";
|
||||||
m_prefixes[loglevel::INFO] = "\r\033[1;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::WARNING] = "\r\033[1;33mwarn: \033[0m";
|
||||||
m_prefixes[loglevel::ERROR] = "\r\033[1;31merror: \033[0m";
|
m_prefixes[loglevel::ERROR] = "\r\033[1;31merror: \033[0m";
|
||||||
m_suffixes[loglevel::TRACE] = "\033[0m";
|
m_suffixes[loglevel::TRACE] = "\033[0m";
|
||||||
m_suffixes[loglevel::INFO] = "\033[0m";
|
m_suffixes[loglevel::INFO] = "\033[0m";
|
||||||
|
m_suffixes[loglevel::NOTICE] = "\033[0m";
|
||||||
m_suffixes[loglevel::WARNING] = "\033[0m";
|
m_suffixes[loglevel::WARNING] = "\033[0m";
|
||||||
m_suffixes[loglevel::ERROR] = "\033[0m";
|
m_suffixes[loglevel::ERROR] = "\033[0m";
|
||||||
} else {
|
} else {
|
||||||
m_prefixes.emplace(make_pair(loglevel::TRACE, "polybar|trace: "));
|
m_prefixes.emplace(make_pair(loglevel::TRACE, "polybar|trace: "));
|
||||||
m_prefixes.emplace(make_pair(loglevel::INFO, "polybar|info: "));
|
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::WARNING, "polybar|warn: "));
|
||||||
m_prefixes.emplace(make_pair(loglevel::ERROR, "polybar|error: "));
|
m_prefixes.emplace(make_pair(loglevel::ERROR, "polybar|error: "));
|
||||||
m_suffixes.emplace(make_pair(loglevel::TRACE, ""));
|
m_suffixes.emplace(make_pair(loglevel::TRACE, ""));
|
||||||
m_suffixes.emplace(make_pair(loglevel::INFO, ""));
|
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::WARNING, ""));
|
||||||
m_suffixes.emplace(make_pair(loglevel::ERROR, ""));
|
m_suffixes.emplace(make_pair(loglevel::ERROR, ""));
|
||||||
}
|
}
|
||||||
@ -77,6 +81,8 @@ loglevel logger::parse_verbosity(const string& name, loglevel fallback) {
|
|||||||
return loglevel::ERROR;
|
return loglevel::ERROR;
|
||||||
} else if (string_util::compare(name, "warning")) {
|
} else if (string_util::compare(name, "warning")) {
|
||||||
return loglevel::WARNING;
|
return loglevel::WARNING;
|
||||||
|
} else if (string_util::compare(name, "notice")) {
|
||||||
|
return loglevel::NOTICE;
|
||||||
} else if (string_util::compare(name, "info")) {
|
} else if (string_util::compare(name, "info")) {
|
||||||
return loglevel::INFO;
|
return loglevel::INFO;
|
||||||
} else if (string_util::compare(name, "trace")) {
|
} else if (string_util::compare(name, "trace")) {
|
||||||
|
@ -16,7 +16,7 @@ int main(int argc, char** argv) {
|
|||||||
const command_line::options opts{
|
const command_line::options opts{
|
||||||
command_line::option{"-h", "--help", "Display this help and exit"},
|
command_line::option{"-h", "--help", "Display this help and exit"},
|
||||||
command_line::option{"-v", "--version", "Display build details 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{"-q", "--quiet", "Be quiet (will override -l)"},
|
||||||
command_line::option{"-c", "--config", "Path to the configuration file", "FILE"},
|
command_line::option{"-c", "--config", "Path to the configuration file", "FILE"},
|
||||||
command_line::option{"-r", "--reload", "Reload when the configuration has been modified"},
|
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};
|
unsigned char exit_code{EXIT_SUCCESS};
|
||||||
bool reload{false};
|
bool reload{false};
|
||||||
|
|
||||||
logger& logger{const_cast<decltype(logger)>(logger::make(loglevel::WARNING))};
|
logger& logger{const_cast<decltype(logger)>(logger::make(loglevel::NOTICE))};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//==================================================
|
//==================================================
|
||||||
|
Loading…
Reference in New Issue
Block a user