From eeccc71c2e6272ab379e7825035187edbe34dfb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tin=20=C5=A0vagelj?= Date: Sat, 4 May 2024 16:02:27 +0200 Subject: [PATCH] Remove logger from libcairo_imlib2_helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Separate logger from logging header. Signed-off-by: Tin Å vagelj --- lua/CMakeLists.txt | 13 +- lua/libcairo_imlib2_helper.h | 22 ++- src/CMakeLists.txt | 4 - src/conky.cc | 1 - src/logger.hh | 332 +++++++++++++++++++++++++++++++++++ src/logging.cc | 54 ------ src/logging.h | 238 +------------------------ src/main.cc | 8 +- 8 files changed, 363 insertions(+), 309 deletions(-) create mode 100644 src/logger.hh delete mode 100644 src/logging.cc diff --git a/lua/CMakeLists.txt b/lua/CMakeLists.txt index af80d47d6..0a2be2ff2 100644 --- a/lua/CMakeLists.txt +++ b/lua/CMakeLists.txt @@ -72,7 +72,7 @@ if(BUILD_LUA_IMLIB2) add_library(conky-imlib2 MODULE ${luaimlib2_src}) set_target_properties(conky-imlib2 PROPERTIES OUTPUT_NAME "imlib2") - target_link_libraries(conky-imlib2 ${luaimlib2_libs} toluapp_lib_static) + target_link_libraries(conky-imlib2 ${luaimlib2_libs} toluapp_lib_static ) set(lua_libs ${lua_libs} conky-imlib2) print_target_properties(conky-imlib2) @@ -83,15 +83,16 @@ if(BUILD_LUA_CAIRO AND BUILD_LUA_IMLIB2) ${CMAKE_CURRENT_SOURCE_DIR}) wrap_tolua(luacairo_imlib2_helper_src cairo_imlib2_helper.pkg) + set(imlib_helper_libs ${luacairo_libs} ${luaimlib2_libs} toluapp_lib_static) + if(BUILD_I18N) + set(imlib_helper_libs ${imlib_helper_libs} -lintl) + endif() + add_library(conky-cairo_imlib2_helper MODULE ${luacairo_imlib2_helper_src}) set_target_properties(conky-cairo_imlib2_helper PROPERTIES OUTPUT_NAME "cairo_imlib2_helper") - target_link_libraries(conky-cairo_imlib2_helper - ${luacairo_libs} - ${luaimlib2_libs} - toluapp_lib_static - conky_logging) + target_link_libraries(conky-cairo_imlib2_helper ${imlib_helper_libs}) set(lua_libs ${lua_libs} conky-cairo_imlib2_helper) endif(BUILD_LUA_CAIRO AND BUILD_LUA_IMLIB2) diff --git a/lua/libcairo_imlib2_helper.h b/lua/libcairo_imlib2_helper.h index 902a45da0..45bffd775 100644 --- a/lua/libcairo_imlib2_helper.h +++ b/lua/libcairo_imlib2_helper.h @@ -28,10 +28,19 @@ #include #include -#include "logging.h" +#include "config.h" -void cairo_place_image(const char *file, cairo_t *cr, int x, int y, - int width, int height, double alpha) { +#ifdef BUILD_I18N +#include +#else +#define gettext +#endif + +#define NORM_ERR(Format, ...) \ + fprintf(stderr, gettext(Format), ##__VA_ARGS__); + +void cairo_place_image(const char *file, cairo_t *cr, int x, int y, int width, + int height, double alpha) { int w, h, stride; Imlib_Image alpha_image, image, premul; cairo_surface_t *result; @@ -83,12 +92,12 @@ void cairo_place_image(const char *file, cairo_t *cr, int x, int y, /* and use the alpha channel of the source image */ imlib_image_copy_alpha_to_image(alpha_image, 0, 0); - stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, width); + stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); /* now pass the result to cairo */ result = cairo_image_surface_create_for_data( - (unsigned char *)imlib_image_get_data_for_reading_only(), CAIRO_FORMAT_ARGB32, - width, height, stride); + (unsigned char *)imlib_image_get_data_for_reading_only(), + CAIRO_FORMAT_ARGB32, width, height, stride); cairo_set_source_surface(cr, result, x, y); cairo_paint_with_alpha(cr, alpha); @@ -101,7 +110,6 @@ void cairo_place_image(const char *file, cairo_t *cr, int x, int y, imlib_free_image(); cairo_surface_destroy(result); - } void cairo_draw_image(const char *file, cairo_surface_t *cs, int x, int y, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b6833d236..d36f4dbc2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -62,10 +62,6 @@ execute_process( COMMAND ${APP_GPERF} --ignore-case -LC++ -Zcolor_name_hash -t -7 -m1 -C -E ) - -add_library(conky_logging logging.cc logging.h) -set(conky_libs ${conky_libs} conky_logging) - set(conky_sources ${conky_sources} c++wrap.cc diff --git a/src/conky.cc b/src/conky.cc index b47863912..4d2660709 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -1912,7 +1912,6 @@ void clean_up(void) { conky::cleanup_config_settings(*state); state.reset(); - conky::log::terminate_logging(); } void handle_terminate() { diff --git a/src/logger.hh b/src/logger.hh new file mode 100644 index 000000000..25e570798 --- /dev/null +++ b/src/logger.hh @@ -0,0 +1,332 @@ +/* + * + * Conky, a system monitor, based on torsmo + * + * Any original torsmo code is licensed under the BSD license + * + * All code written since the fork of torsmo is licensed under the GPL + * + * Please see COPYING for details + * + * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen + * Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al. + * (see AUTHORS) + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef _CONKY_LOGGER_H +#define _CONKY_LOGGER_H + +#include "config.h" + +#include "i18n.h" + +#include +#include +#include +#include // correct formatting for int types +#include +#include +#include +#include +#include +#include +#include + +#if __has_include() +#define HAS_SYSLOG +#endif + +#ifdef HAS_SYSLOG +extern "C" { +#include +// hide syslog level definitions +#undef LOG_EMERG +#undef LOG_ALERT +#undef LOG_CRIT +#undef LOG_ERR +#undef LOG_WARNING +#undef LOG_NOTICE +#undef LOG_INFO +#undef LOG_DEBUG +} +#endif /* HAS_SYSLOG */ + +namespace conky::log { +/// @brief Logging levels. +/// +/// Values match syslog ones, with addition of `TRACE` which is local. +/// `Emergency` (0) and `Alert` (1) are not used as they're not warranted from a +/// userspace application. +enum class level { + OFF = 1, + CRITICAL = 2, + ERROR = 3, + WARNING = 4, + NOTICE = 5, + INFO = 6, + /// @brief Debug information. + /// + /// Previously DBGP. + DEBUG = 7, + /// @brief Very detailed information useful for debugging purposes. + /// + /// Previously DBGP2. + TRACE = 8, +}; + +const auto level_names = std::array{ + "CRITICAL", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG", "TRACE", +}; +const size_t MAX_LEVEL_NAME_LEN = 8; + +constexpr inline const char *log_level_to_cstr(level log_level) { + return level_names[static_cast(log_level) - 2]; +} + +using clock = std::chrono::system_clock; +using instant = clock::time_point; + +struct source_details { + const char *file = nullptr; + size_t line; +}; + +struct log_details { + std::optional source; + std::optional time; +}; + +static const size_t TIME_LEN = 24; + +namespace _priv { +inline size_t format_log_time(char *out, size_t max_len, instant time) { + std::time_t current_time = std::chrono::system_clock::to_time_t(time); + auto millis = std::chrono::duration_cast( + time.time_since_epoch()); + struct tm local_time; + localtime_r(¤t_time, &local_time); + size_t time_len = 0; + time_len += std::strftime(out, max_len, "%F %T", &local_time); + time_len += snprintf(&out[time_len], max_len - time_len, ".%03d", + static_cast(millis.count() % 1000)); + + return time_len; +} + +inline size_t format_log_time(FILE *out, size_t max_len, instant time) { + char buffer[TIME_LEN]; + size_t result = format_log_time(&buffer[0], max_len, time); + fprintf(out, "%s", buffer); + return result; +} + +#define VAL_AND_LEN(STR) (std::make_pair("][" STR "]", sizeof(STR) + 3)) +const std::array, 7> _FMT_DATA{ + VAL_AND_LEN("CRITICAL"), VAL_AND_LEN("ERROR"), VAL_AND_LEN("WARNING"), + VAL_AND_LEN("NOTICE"), VAL_AND_LEN("INFO"), VAL_AND_LEN("DEBUG"), + VAL_AND_LEN("TRACE"), +}; +#undef VAL_AND_LEN +constexpr inline const char *_log_level_fmt(level log_level) { + return _FMT_DATA[static_cast(log_level) - 2].first; +} +constexpr inline size_t _log_level_fmt_len(level log_level) { + return _FMT_DATA[static_cast(log_level) - 2].second; +} + +/// @brief Given some `base` path string view, returns last part of the string +/// that contains (starts with) `/src/`. If no such path is found, `begin` of +/// `base` is returned instead. First `/` character is excluded from result. +/// +/// @note Provided `base` should (but doesn't have to) be a null terminated +/// string. +/// +/// @param base string to trim +/// @return start of `base` or ending that starts with `/src/` +constexpr const char *relative_source_path(const std::string_view &base) { + // leave space to lookup previous "/src/" characters + auto last = base.begin() + 5; + for (auto it = base.end(); it != last; it--) { + if (*it == '/' && *(it - 1) == 'c' && *(it - 2) == 'r' && + *(it - 3) == 's' && *(it - 4) == '/') { + return it - 3; + } + } + return base.begin(); +} + +template +inline void _impl_syslog(level log_level, const char *format, Args &&...args) { + syslog(static_cast(log_level), format, args...); +} +inline void _impl_syslog(level log_level, const char *format) { + syslog(static_cast(log_level), "%s", format); +} + +template +inline void _impl_fprintf(FILE *out, const char *format, Args &&...args) { + fprintf(out, format, args...); +} +inline void _impl_fprintf(FILE *out, const char *format) { + fprintf(out, "%s", format); +} +} // namespace _priv + +const size_t MAX_LOG_TARGETS = 5; +const level DEFAULT_LOG_LEVEL = level::NOTICE; +struct logger { + struct log_target { + FILE *stream = nullptr; + level log_level = DEFAULT_LOG_LEVEL; + + public: + bool is_enabled(level log_level) const { + return static_cast(this->log_level) >= static_cast(log_level); + } + void set_log_level(level log_level) { this->log_level = log_level; } + void log_more() { + this->log_level = + static_cast(std::min(static_cast(this->log_level) + 1, + static_cast(level::TRACE))); + } + void log_less() { + this->log_level = static_cast(std::max( + static_cast(this->log_level) - 1, static_cast(level::OFF))); + } + }; + + private: + const char *name; + std::array entries; + + size_t check_available() const { + for (size_t i = 0; i < MAX_LOG_TARGETS; i++) { + if (entries[i].stream == nullptr) return MAX_LOG_TARGETS - i; + } + return 0; + } + + bool is_any_enabled(level log_level) const { + for (size_t i = 0; i < MAX_LOG_TARGETS; i++) { + if (this->entries.at(i).is_enabled(log_level)) return true; + } + return false; + } + + public: + logger(const char *name) : name(name) { + this->entries[0] = log_target{ + stderr, + level::NOTICE, + }; + +#ifdef HAS_SYSLOG + openlog(PACKAGE_NAME, LOG_PID, LOG_USER); +#else + use_log_file(); +#endif + } + ~logger() { + for (auto &entry : this->entries) { + if (entry.stream != nullptr) { + fclose(entry.stream); + entry.stream = nullptr; + } + } + +#ifdef HAS_SYSLOG + closelog(); +#endif + } + + const log_target *add_log_file(const std::string &path) { + int available = check_available(); + if (available < 0) { return nullptr; } + this->entries[available].stream = fopen(path.c_str(), "a+"); + this->entries[available].log_level = DEFAULT_LOG_LEVEL; + return &this->entries[available]; + } + + log_target *get_stream_target(FILE *stream) { + for (size_t i = 0; i < MAX_LOG_TARGETS; i++) { + if (this->entries[i].stream == stream) { return &this->entries[i]; } + } + return nullptr; + } + + template + inline void log_print_fmt(log_details &&details, const char *format, + Args &&...args) { +#ifdef HAS_SYSLOG + if constexpr (static_cast(log_level) >= + static_cast(level::CRITICAL) && + static_cast(log_level) < + static_cast(level::TRACE)) { + _priv::_impl_syslog(log_level, format, args...); + } +#endif + + if (!is_any_enabled(log_level)) return; + + static const size_t MAX_FILE_LEN = 32; + static const size_t MAX_LOCATION_LEN = MAX_FILE_LEN + 1 + 5; // name:line + static const size_t PREAMBLE_LENGTH = + 2 + TIME_LEN + 2 + MAX_LEVEL_NAME_LEN + 2 + MAX_LOCATION_LEN; + char preamble[PREAMBLE_LENGTH + 1] = "["; + size_t offset = 1; + // append time + offset += _priv::format_log_time(&preamble[offset], TIME_LEN, + details.time.value_or(clock::now())); + // append log level + std::strncat(&preamble[offset], _priv::_log_level_fmt(log_level), + _priv::_log_level_fmt_len(log_level)); + offset += _priv::_log_level_fmt_len(log_level) - 1; + // append source information + if (details.source.has_value()) { + auto source = details.source.value(); + offset += snprintf(&preamble[offset], PREAMBLE_LENGTH - offset, + "[%s:%ld]", source.file, source.line); + } + + // localized output to console + for (const auto &target : this->entries) { + if (!target.is_enabled(log_level)) continue; + fprintf(target.stream, "%s: ", preamble); + _priv::_impl_fprintf(target.stream, _(format), args...); + fputs("\n", target.stream); + } + } + + template + void log_location(const char *file, size_t line, const char *format, + Args &&...args) { + this->log_print_fmt( + log_details{ + std::optional(source_details{file, line}), + }, + format, args...); + } + + template + void log(const char *format, Args &&...args) { + this->log_print_fmt(log_details{}, format, args...); + } +}; + +} // namespace conky::log + +#endif /* _CONKY_LOGGER_H */ diff --git a/src/logging.cc b/src/logging.cc deleted file mode 100644 index 378c94c7a..000000000 --- a/src/logging.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "logging.h" - -#include - -namespace conky::log { -static const char *DEFAULT_LOG_PATH = "/tmp/conky.log"; - -static level current_log_level = level::DEBUG; - -bool is_enabled(level log_level) { - return static_cast(current_log_level) >= static_cast(log_level); -} -void set_log_level(level log_level) { current_log_level = log_level; } -void log_more() { - current_log_level = static_cast(std::min( - static_cast(current_log_level) + 1, static_cast(level::TRACE))); -} -void log_less() { - current_log_level = static_cast(std::max( - static_cast(current_log_level) - 1, static_cast(level::OFF))); -} - -static std::array LOG_STREAMS{stderr, nullptr}; -void use_log_file(const char *path) { - if (LOG_STREAMS[1] != nullptr) { fclose(LOG_STREAMS[1]); } - - if (path != nullptr) { - LOG_STREAMS[1] = fopen(path, "a+"); - } else { - LOG_STREAMS[1] = fopen(DEFAULT_LOG_PATH, "a+"); - } -} - -void init_system_logging() { -#ifdef HAS_SYSLOG - openlog(PACKAGE_NAME, LOG_PID, LOG_USER); -#else - use_log_file(); -#endif -} - -FILE **_log_streams() { return LOG_STREAMS.data(); }; - -void terminate_logging() { - if (LOG_STREAMS[1] != nullptr) { - fclose(LOG_STREAMS[1]); - LOG_STREAMS[1] = nullptr; - } -#ifdef HAS_SYSLOG - closelog(); -#endif -} - -} // namespace conky::log \ No newline at end of file diff --git a/src/logging.h b/src/logging.h index c40d07813..90bbce7a2 100644 --- a/src/logging.h +++ b/src/logging.h @@ -30,40 +30,7 @@ #ifndef _LOGGING_H #define _LOGGING_H -#include "config.h" - -#include "i18n.h" - -#include -#include -#include // correct formatting for int types -#include -#include -#include -#include -#include -#include -#include -#include - -#if __has_include() -#define HAS_SYSLOG -#endif - -#ifdef HAS_SYSLOG -extern "C" { -#include -// hide syslog level definitions -#undef LOG_EMERG -#undef LOG_ALERT -#undef LOG_CRIT -#undef LOG_ERR -#undef LOG_WARNING -#undef LOG_NOTICE -#undef LOG_INFO -#undef LOG_DEBUG -} -#endif /* HAS_SYSLOG */ +#include "logger.hh" class fork_throw : public std::runtime_error { public: @@ -91,205 +58,10 @@ class obj_create_error : public std::runtime_error { obj_create_error(const std::string &msg) : std::runtime_error(msg) {} }; -namespace conky::log { -/// @brief Logging levels. -/// -/// Values match syslog ones, with addition of `TRACE` which is local. -/// `Emergency` (0) and `Alert` (1) are not used as they're not warranted from a -/// userspace application. -enum class level { - OFF = 1, - CRITICAL = 2, - ERROR = 3, - WARNING = 4, - NOTICE = 5, - INFO = 6, - /// @brief Debug information. - /// - /// Previously DBGP. - DEBUG = 7, - /// @brief Very detailed information useful for debugging purposes. - /// - /// Previously DBGP2. - TRACE = 8, -}; - -const auto level_names = std::array{ - "CRITICAL", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG", "TRACE", -}; -const size_t MAX_LEVEL_NAME_LEN = 8; - -constexpr inline const char *log_level_to_cstr(level log_level) { - return level_names[static_cast(log_level) - 2]; -} - -bool is_enabled(level log_level); -void set_log_level(level log_level); -void log_more(); -void log_less(); - -/// Implementation detail: -/// 0 - console output -/// 1 - file output -FILE **_log_streams(); -void use_log_file(const char *path = nullptr); -void init_system_logging(); -void terminate_logging(); - -using clock = std::chrono::system_clock; -using instant = clock::time_point; - -struct source_details { - const char *file = nullptr; - size_t line; -}; - -struct log_details { - std::optional source; - std::optional time; -}; - -static const size_t TIME_LEN = 24; - -namespace _priv { -inline size_t format_log_time(char *out, size_t max_len, instant time) { - std::time_t current_time = std::chrono::system_clock::to_time_t(time); - auto millis = std::chrono::duration_cast( - time.time_since_epoch()); - struct tm local_time; - localtime_r(¤t_time, &local_time); - size_t time_len = 0; - time_len += std::strftime(out, max_len, "%F %T", &local_time); - time_len += snprintf(&out[time_len], max_len - time_len, ".%03d", - static_cast(millis.count() % 1000)); - - return time_len; -} - -inline size_t format_log_time(FILE *out, size_t max_len, instant time) { - char buffer[TIME_LEN]; - size_t result = format_log_time(&buffer[0], max_len, time); - fprintf(out, "%s", buffer); - return result; -} - -#define VAL_AND_LEN(STR) (std::make_pair("][" STR "]", sizeof(STR) + 3)) -const std::array, 7> _FMT_DATA{ - VAL_AND_LEN("CRITICAL"), VAL_AND_LEN("ERROR"), VAL_AND_LEN("WARNING"), - VAL_AND_LEN("NOTICE"), VAL_AND_LEN("INFO"), VAL_AND_LEN("DEBUG"), - VAL_AND_LEN("TRACE"), -}; -#undef VAL_AND_LEN -constexpr inline const char *_log_level_fmt(level log_level) { - return _FMT_DATA[static_cast(log_level) - 2].first; -} -constexpr inline size_t _log_level_fmt_len(level log_level) { - return _FMT_DATA[static_cast(log_level) - 2].second; -} - -/// @brief Given some `base` path string view, returns last part of the string -/// that contains (starts with) `/src/`. If no such path is found, `begin` of -/// `base` is returned instead. First `/` character is excluded from result. -/// -/// @note Provided `base` should (but doesn't have to) be a null terminated -/// string. -/// -/// @param base string to trim -/// @return start of `base` or ending that starts with `/src/` -constexpr const char *relative_source_path(const std::string_view &base) { - // leave space to lookup previous "/src/" characters - auto last = base.begin() + 5; - for (auto it = base.end(); it != last; it--) { - if (*it == '/' && *(it - 1) == 'c' && *(it - 2) == 'r' && - *(it - 3) == 's' && *(it - 4) == '/') { - return it - 3; - } - } - return base.begin(); -} - -template -inline void _impl_syslog(level log_level, const char *format, Args &&...args) { - syslog(static_cast(log_level), format, args...); -} -inline void _impl_syslog(level log_level, const char *format) { - syslog(static_cast(log_level), "%s", format); -} - -template -inline void _impl_fprintf(FILE *out, const char *format, Args &&...args) { - fprintf(out, format, args...); -} -inline void _impl_fprintf(FILE *out, const char *format) { - fprintf(out, "%s", format); -} -} // namespace _priv - -template -inline void log_print_fmt(log_details &&details, const char *format, - Args &&...args) { -#ifdef HAS_SYSLOG - if constexpr (static_cast(log_level) >= - static_cast(level::CRITICAL) && - static_cast(log_level) < static_cast(level::TRACE)) { - _priv::_impl_syslog(log_level, format, args...); - } -#endif - - auto streams = _log_streams(); - if (!is_enabled(log_level) && streams[1] != nullptr) return; - - static const size_t MAX_FILE_LEN = 32; - static const size_t MAX_LOCATION_LEN = MAX_FILE_LEN + 1 + 5; // name:line - static const size_t PREAMBLE_LENGTH = - 2 + TIME_LEN + 2 + MAX_LEVEL_NAME_LEN + 2 + MAX_LOCATION_LEN; - char preamble[PREAMBLE_LENGTH + 1] = "["; - size_t offset = 1; - // append time - offset += _priv::format_log_time(&preamble[offset], TIME_LEN, - details.time.value_or(clock::now())); - // append log level - std::strncat(&preamble[offset], _priv::_log_level_fmt(log_level), - _priv::_log_level_fmt_len(log_level)); - offset += _priv::_log_level_fmt_len(log_level) - 1; - // append source information - if (details.source.has_value()) { - auto source = details.source.value(); - offset += snprintf(&preamble[offset], PREAMBLE_LENGTH - offset, "[%s:%ld]", - source.file, source.line); - } - - // localized output to console - if (is_enabled(log_level)) { - fprintf(streams[0], "%s: ", preamble); - _priv::_impl_fprintf(streams[0], _(format), args...); - fputs("\n", streams[0]); - } - // unlocalized output to file - if (streams[1] != nullptr) { - fprintf(streams[1], "%s: ", preamble); - _priv::_impl_fprintf(streams[1], format, args...); - fputs("\n", streams[1]); - } -} - -template -void log_location(const char *file, size_t line, const char *format, - Args &&...args) { - log_print_fmt( - log_details{ - std::optional(source_details{file, line}), - }, - format, args...); -} - -template -void log(const char *format, Args &&...args) { - log_print_fmt(log_details{}, format, args...); -} +extern conky::log::logger DEFAULT_LOGGER; #define LOG(Level, ...) \ - ::conky::log::log_location<::conky::log::level::Level>( \ + DEFAULT_LOGGER.log_location<::conky::log::level::Level>( \ ::conky::log::_priv::relative_source_path(__FILE__), __LINE__, \ __VA_ARGS__) @@ -301,8 +73,6 @@ void log(const char *format, Args &&...args) { #define LOG_DEBUG(...) LOG(DEBUG, __VA_ARGS__) #define LOG_TRACE(...) LOG(TRACE, __VA_ARGS__) -} // namespace conky::log - // backwards compatibility aliases #define NORM_ERR(...) LOG_INFO(__VA_ARGS__) #define DBGP(...) LOG_DEBUG(__VA_ARGS__) @@ -333,7 +103,7 @@ inline std::string alloc_printf(const char *format) { class error : public std::runtime_error { public: - error(const char *msg) : std::runtime_error(std::string(_(msg))) {} + error(const char *msg) : error(std::string(_(msg))) {} template error(const char *format, Args &&...args) : error(_priv_error_print::alloc_printf(_(format), args...)) {} diff --git a/src/main.cc b/src/main.cc index 57eb6dc04..16bda45cf 100644 --- a/src/main.cc +++ b/src/main.cc @@ -281,9 +281,10 @@ inline void reset_optind() { #endif } +conky::log::logger DEFAULT_LOGGER("conky"); + int main(int argc, char **argv) { std::set_terminate(&handle_terminate); - conky::log::init_system_logging(); #ifdef BUILD_I18N setlocale(LC_ALL, ""); @@ -323,7 +324,7 @@ int main(int argc, char **argv) { switch (c) { case 'D': - conky::log::log_more(); + DEFAULT_LOGGER.get_stream_target(stderr)->log_more(); break; case 'v': print_version(); @@ -335,7 +336,8 @@ int main(int argc, char **argv) { current_config = optarg; break; case 'q': - conky::log::set_log_level(conky::log::level::OFF); + DEFAULT_LOGGER.get_stream_target(stderr)->set_log_level( + conky::log::level::OFF); break; case 'h': print_help(argv[0]);