2018-05-12 16:03:00 +00:00
|
|
|
/*
|
2009-07-28 21:44:22 +00:00
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
2008-12-15 21:40:24 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-02-27 15:14:19 +00:00
|
|
|
* Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
|
2008-12-15 21:40:24 +00:00
|
|
|
* (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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2009-07-08 13:51:08 +00:00
|
|
|
|
2010-02-23 22:59:03 +00:00
|
|
|
#ifndef _LOGGING_H
|
|
|
|
#define _LOGGING_H
|
|
|
|
|
2023-11-13 18:01:41 +00:00
|
|
|
#include <cinttypes> // correct formatting for int types
|
2023-11-10 11:31:01 +00:00
|
|
|
#include <cstdio>
|
2010-11-14 17:19:46 +00:00
|
|
|
#include <stdexcept>
|
2018-05-12 16:03:00 +00:00
|
|
|
#include "config.h"
|
2010-11-13 18:45:04 +00:00
|
|
|
#include "i18n.h"
|
2010-02-18 00:25:32 +00:00
|
|
|
|
2010-11-15 16:52:42 +00:00
|
|
|
class fork_throw : public std::runtime_error {
|
2018-05-12 16:03:00 +00:00
|
|
|
public:
|
|
|
|
fork_throw() : std::runtime_error("Fork happened") {}
|
|
|
|
fork_throw(const std::string &msg) : std::runtime_error(msg) {}
|
2010-11-15 16:52:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class unknown_arg_throw : public std::runtime_error {
|
2018-05-12 16:03:00 +00:00
|
|
|
public:
|
|
|
|
unknown_arg_throw() : std::runtime_error("Unknown argumunt given") {}
|
|
|
|
unknown_arg_throw(const std::string &msg) : std::runtime_error(msg) {}
|
2010-11-15 16:52:42 +00:00
|
|
|
};
|
2010-11-15 16:07:38 +00:00
|
|
|
|
2010-11-16 12:41:44 +00:00
|
|
|
class combine_needs_2_args_error : public std::runtime_error {
|
2018-05-12 16:03:00 +00:00
|
|
|
public:
|
|
|
|
combine_needs_2_args_error()
|
|
|
|
: std::runtime_error("combine needs arguments: <text1> <text2>") {}
|
|
|
|
combine_needs_2_args_error(const std::string &msg)
|
|
|
|
: std::runtime_error(msg) {}
|
2010-11-16 12:41:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class obj_create_error : public std::runtime_error {
|
2018-05-12 16:03:00 +00:00
|
|
|
public:
|
|
|
|
obj_create_error() : std::runtime_error("Failed to create object") {}
|
|
|
|
obj_create_error(const std::string &msg) : std::runtime_error(msg) {}
|
2010-11-16 12:41:44 +00:00
|
|
|
};
|
|
|
|
|
2023-05-05 01:02:35 +00:00
|
|
|
void clean_up(void);
|
2009-08-07 07:21:56 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
template <typename... Args>
|
2021-01-24 14:44:28 +00:00
|
|
|
inline void gettextize_format(const char *format, Args &&...args) {
|
2018-05-12 16:03:00 +00:00
|
|
|
fprintf(stderr, _(format), args...);
|
|
|
|
}
|
2010-11-12 18:33:17 +00:00
|
|
|
|
2018-05-12 16:03:00 +00:00
|
|
|
// explicit specialization for no arguments to avoid the
|
2010-11-12 18:33:17 +00:00
|
|
|
// "format not a string literal and no format arguments" warning
|
2018-05-12 16:03:00 +00:00
|
|
|
inline void gettextize_format(const char *format) { fputs(_(format), stderr); }
|
2010-11-12 18:33:17 +00:00
|
|
|
|
2018-05-13 01:09:24 +00:00
|
|
|
template <typename... Args>
|
2021-01-24 14:44:28 +00:00
|
|
|
void NORM_ERR(const char *format, Args &&...args) {
|
2018-05-13 01:09:24 +00:00
|
|
|
fprintf(stderr, PACKAGE_NAME ": ");
|
|
|
|
gettextize_format(format, args...);
|
|
|
|
fputs("\n", stderr);
|
|
|
|
}
|
2008-12-15 21:40:24 +00:00
|
|
|
|
2023-05-05 01:24:55 +00:00
|
|
|
/* critical error with additional cleanup */
|
2018-05-13 01:09:24 +00:00
|
|
|
template <typename... Args>
|
2023-11-10 11:31:01 +00:00
|
|
|
__attribute__((noreturn)) inline void CRIT_ERR_FREE(void *memtofree1,
|
|
|
|
void *memtofree2,
|
|
|
|
const char *format,
|
|
|
|
Args &&...args) {
|
2018-05-13 01:09:24 +00:00
|
|
|
NORM_ERR(format, args...);
|
2023-05-05 01:02:35 +00:00
|
|
|
free(memtofree1);
|
|
|
|
free(memtofree2);
|
|
|
|
clean_up();
|
2018-05-13 01:09:24 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2008-12-15 21:40:24 +00:00
|
|
|
|
2023-05-05 01:24:55 +00:00
|
|
|
/* critical error */
|
|
|
|
template <typename... Args>
|
2023-11-10 11:31:01 +00:00
|
|
|
__attribute__((noreturn)) inline void CRIT_ERR(const char *format,
|
|
|
|
Args &&...args) {
|
2023-05-05 01:24:55 +00:00
|
|
|
CRIT_ERR_FREE(nullptr, nullptr, format, args...);
|
|
|
|
}
|
|
|
|
|
2010-11-14 23:24:49 +00:00
|
|
|
namespace conky {
|
2018-05-12 16:03:00 +00:00
|
|
|
class error : public std::runtime_error {
|
|
|
|
public:
|
|
|
|
error(const std::string &msg) : std::runtime_error(msg) {}
|
|
|
|
};
|
|
|
|
} // namespace conky
|
2010-11-14 17:19:46 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
/* debugging output */
|
|
|
|
extern int global_debug_level;
|
2018-08-03 16:22:11 +00:00
|
|
|
|
|
|
|
#define __DBGP(level, ...) \
|
|
|
|
do { \
|
|
|
|
if (global_debug_level > level) { \
|
|
|
|
fprintf(stderr, "DEBUG(%d) [" __FILE__ ":%d]: ", level, __LINE__); \
|
|
|
|
gettextize_format(__VA_ARGS__); \
|
|
|
|
fputs("\n", stderr); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#define DBGP(...) __DBGP(0, __VA_ARGS__)
|
|
|
|
#define DBGP2(...) __DBGP(1, __VA_ARGS__)
|
2008-12-15 21:40:24 +00:00
|
|
|
|
|
|
|
#endif /* _LOGGING_H */
|