From cae3848030669ff541b3d8b32746494d9245d267 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Wed, 22 Apr 2020 00:12:08 +0200
Subject: [PATCH] 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.
---
contrib/bash/polybar | 1 +
contrib/zsh/_polybar | 2 +-
doc/man/polybar.1.rst | 4 ++--
include/components/logger.hpp | 9 +++++++++
src/components/logger.cpp | 6 ++++++
src/main.cpp | 4 ++--
6 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/contrib/bash/polybar b/contrib/bash/polybar
index d8a40de6..88e7b7c2 100644
--- a/contrib/bash/polybar
+++ b/contrib/bash/polybar
@@ -42,6 +42,7 @@ _polybar() {
local log_levels='error
warning
+ notice
info
trace'
diff --git a/contrib/zsh/_polybar b/contrib/zsh/_polybar
index 94c43a48..09f99a68 100644
--- a/contrib/zsh/_polybar
+++ b/contrib/zsh/_polybar
@@ -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]' \
diff --git a/doc/man/polybar.1.rst b/doc/man/polybar.1.rst
index 08f052dc..a1f2ec7b 100644
--- a/doc/man/polybar.1.rst
+++ b/doc/man/polybar.1.rst
@@ -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)
diff --git a/include/components/logger.hpp b/include/components/logger.hpp
index 437446ce..5c7d1ba2 100644
--- a/include/components/logger.hpp
+++ b/include/components/logger.hpp
@@ -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)...);
}
+ /**
+ * Output a notice
+ */
+ template
+ void notice(const string& message, Args&&... args) const {
+ output(loglevel::NOTICE, message, std::forward(args)...);
+ }
+
/**
* Output a warning message
*/
diff --git a/src/components/logger.cpp b/src/components/logger.cpp
index 30913540..f482eeaf 100644
--- a/src/components/logger.cpp
+++ b/src/components/logger.cpp
@@ -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")) {
diff --git a/src/main.cpp b/src/main.cpp
index b3996025..4f61876c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -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(logger::make(loglevel::WARNING))};
+ logger& logger{const_cast(logger::make(loglevel::NOTICE))};
try {
//==================================================