1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-10-02 15:09:07 +00:00
conky/src/logging.h
Pavel Labath 9a08141389 Fix the "ISO C does not permit named variadic macros" in maintainer mode
and a few other that have cropped up in the process
2010-11-12 19:48:06 +01:00

75 lines
2.5 KiB
C++

/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
*
* 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-2010 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 <http://www.gnu.org/licenses/>.
*
*/
#ifndef _LOGGING_H
#define _LOGGING_H
#include <cstdio>
#include <libintl.h>
#include "mail.h"
void clean_up(void *memtofree1, void* memtofree2);
void clean_up_without_threads(void *memtofree1, void* memtofree2);
template<typename... Args>
void gettextize_format(const char *format, Args&&... args)
{ fprintf(stderr, gettext(format), args...); }
// explicit specialization for no arguments to avoid the
// "format not a string literal and no format arguments" warning
inline void gettextize_format(const char *format)
{ fputs(gettext(format), stderr); }
#define NORM_ERR(...) do { \
fprintf(stderr, PACKAGE_NAME": "); \
gettextize_format(__VA_ARGS__); \
fputs("\n", stderr); \
} while(0)
/* critical error */
#define CRIT_ERR(memtofree1, memtofree2, ...) \
{ NORM_ERR(__VA_ARGS__); clean_up(memtofree1, memtofree2); free(current_mail_spool); exit(EXIT_FAILURE); }
#define THREAD_CRIT_ERR(memtofree1, memtofree2, ...) \
{ NORM_ERR(__VA_ARGS__); clean_up_without_threads(memtofree1, memtofree2); free(current_mail_spool); return; }
/* debugging output */
extern int global_debug_level;
#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__)
#endif /* _LOGGING_H */