wip(refactor): Improve signal and event handling
This commit is contained in:
parent
d45fd76dcd
commit
08be86fbe1
73 changed files with 2228 additions and 2251 deletions
include/components
|
@ -1,13 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
enum class loglevel {
|
||||
enum class loglevel : uint8_t {
|
||||
NONE = 0,
|
||||
ERROR,
|
||||
WARNING,
|
||||
|
@ -25,34 +27,26 @@ class logger {
|
|||
void verbosity(loglevel level);
|
||||
void verbosity(string level);
|
||||
|
||||
/**
|
||||
* Output a trace message
|
||||
*/
|
||||
#ifdef DEBUG_LOGGER // {{{
|
||||
template <typename... Args>
|
||||
#ifdef DEBUG_LOGGER
|
||||
void trace(string message, Args... args) const {
|
||||
output(loglevel::TRACE, message, args...);
|
||||
}
|
||||
#else
|
||||
#ifdef VERBOSE_TRACELOG
|
||||
#undef VERBOSE_TRACELOG
|
||||
#endif
|
||||
void trace(string, Args...) const {
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Output extra verbose trace message
|
||||
*/
|
||||
template <typename... Args>
|
||||
#ifdef VERBOSE_TRACELOG
|
||||
void trace_x(string message, Args... args) const {
|
||||
output(loglevel::TRACE, message, args...);
|
||||
}
|
||||
#else
|
||||
void trace_x(string, Args...) const {
|
||||
}
|
||||
template <typename... Args>
|
||||
void trace_x(Args...) const {}
|
||||
#endif
|
||||
#else
|
||||
template <typename... Args>
|
||||
void trace(Args...) const {}
|
||||
template <typename... Args>
|
||||
void trace_x(Args...) const {}
|
||||
#endif // }}}
|
||||
|
||||
/**
|
||||
* Output an info message
|
||||
|
@ -97,70 +91,56 @@ class logger {
|
|||
*/
|
||||
template <typename... Args>
|
||||
void output(loglevel level, string format, Args... values) const {
|
||||
if (level > m_level)
|
||||
if (level > m_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto prefix = m_prefixes.find(level)->second;
|
||||
auto suffix = m_suffixes.find(level)->second;
|
||||
|
||||
// silence the compiler
|
||||
#if defined(__clang__)
|
||||
#if defined(__clang__) // {{{
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wformat-security"
|
||||
#elif defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-security"
|
||||
#endif
|
||||
dprintf(m_fd, (prefix + format + suffix + "\n").c_str(), convert(values)...);
|
||||
#if defined(__clang__)
|
||||
#endif // }}}
|
||||
|
||||
dprintf(m_fd, (m_prefixes.at(level) + format + m_suffixes.at(level) + "\n").c_str(), convert(values)...);
|
||||
|
||||
#if defined(__clang__) // {{{
|
||||
#pragma clang diagnostic pop
|
||||
#elif defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#endif // }}}
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Logger verbosity level
|
||||
*/
|
||||
loglevel m_level = loglevel::TRACE;
|
||||
loglevel m_level{loglevel::TRACE};
|
||||
|
||||
/**
|
||||
* File descriptor used when writing the log messages
|
||||
*/
|
||||
int m_fd = STDERR_FILENO;
|
||||
int m_fd{STDERR_FILENO};
|
||||
|
||||
/**
|
||||
* Loglevel specific prefixes
|
||||
*/
|
||||
// clang-format off
|
||||
map<loglevel, string> m_prefixes {
|
||||
{loglevel::TRACE, "polybar|trace "},
|
||||
{loglevel::INFO, "polybar|info "},
|
||||
{loglevel::WARNING, "polybar|warn "},
|
||||
{loglevel::ERROR, "polybar|error "},
|
||||
};
|
||||
std::map<loglevel, string> m_prefixes;
|
||||
|
||||
/**
|
||||
* Loglevel specific suffixes
|
||||
*/
|
||||
map<loglevel, string> m_suffixes {
|
||||
{loglevel::TRACE, ""},
|
||||
{loglevel::INFO, ""},
|
||||
{loglevel::WARNING, ""},
|
||||
{loglevel::ERROR, ""},
|
||||
};
|
||||
// clang-format on
|
||||
std::map<loglevel, string> m_suffixes;
|
||||
};
|
||||
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
template <typename T = const logger&>
|
||||
di::injector<T> configure_logger(loglevel level = loglevel::NONE) {
|
||||
auto instance = factory_util::generic_singleton<logger>(level);
|
||||
return di::make_injector(di::bind<>().to(instance));
|
||||
inline const logger& make_logger(loglevel level = loglevel::NONE) {
|
||||
auto instance = factory_util::singleton<const logger>(level);
|
||||
return static_cast<const logger&>(*instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue