|
Packit |
9c3e7e |
/**
|
|
Packit |
9c3e7e |
* @file print.h
|
|
Packit |
9c3e7e |
* @brief Logging support functions
|
|
Packit |
9c3e7e |
* @note Copyright (C) 2011 Richard Cochran <richardcochran@gmail.com>
|
|
Packit |
9c3e7e |
*
|
|
Packit |
9c3e7e |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
9c3e7e |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
9c3e7e |
* the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
9c3e7e |
* (at your option) any later version.
|
|
Packit |
9c3e7e |
*
|
|
Packit |
9c3e7e |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
9c3e7e |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
9c3e7e |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
9c3e7e |
* GNU General Public License for more details.
|
|
Packit |
9c3e7e |
*
|
|
Packit |
9c3e7e |
* You should have received a copy of the GNU General Public License along
|
|
Packit |
9c3e7e |
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit |
9c3e7e |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit |
9c3e7e |
*/
|
|
Packit |
9c3e7e |
#ifndef HAVE_PRINT_H
|
|
Packit |
9c3e7e |
#define HAVE_PRINT_H
|
|
Packit |
9c3e7e |
|
|
Packit |
9c3e7e |
#include <syslog.h>
|
|
Packit |
9c3e7e |
|
|
Packit |
9c3e7e |
#include "util.h"
|
|
Packit |
9c3e7e |
|
|
Packit |
9c3e7e |
#define PRINT_LEVEL_MIN LOG_EMERG
|
|
Packit |
9c3e7e |
#define PRINT_LEVEL_MAX LOG_DEBUG
|
|
Packit |
9c3e7e |
|
|
Packit |
9c3e7e |
#ifdef __GNUC__
|
|
Packit |
9c3e7e |
__attribute__ ((format (printf, 2, 3)))
|
|
Packit |
9c3e7e |
#endif
|
|
Packit |
9c3e7e |
void print(int level, char const *format, ...);
|
|
Packit |
9c3e7e |
|
|
Packit |
9c3e7e |
void print_set_progname(const char *name);
|
|
Packit |
9c3e7e |
void print_set_tag(const char *tag);
|
|
Packit |
9c3e7e |
void print_set_syslog(int value);
|
|
Packit |
9c3e7e |
void print_set_level(int level);
|
|
Packit |
9c3e7e |
void print_set_verbose(int value);
|
|
Packit |
9c3e7e |
|
|
Packit |
9c3e7e |
#define pr_emerg(x...) print(LOG_EMERG, x)
|
|
Packit |
9c3e7e |
#define pr_alert(x...) print(LOG_ALERT, x)
|
|
Packit |
9c3e7e |
#define pr_crit(x...) print(LOG_CRIT, x)
|
|
Packit |
9c3e7e |
#define pr_err(x...) print(LOG_ERR, x)
|
|
Packit |
9c3e7e |
#define pr_warning(x...) print(LOG_WARNING, x)
|
|
Packit |
9c3e7e |
#define pr_notice(x...) print(LOG_NOTICE, x)
|
|
Packit |
9c3e7e |
#define pr_info(x...) print(LOG_INFO, x)
|
|
Packit |
9c3e7e |
#define pr_debug(x...) print(LOG_DEBUG, x)
|
|
Packit |
9c3e7e |
|
|
Packit |
9c3e7e |
#define PRINT_RL(l, i, x...) \
|
|
Packit |
9c3e7e |
do { \
|
|
Packit |
9c3e7e |
static time_t last = -i; \
|
|
Packit |
9c3e7e |
if (!rate_limited(i, &last)) \
|
|
Packit |
9c3e7e |
print(l, x); \
|
|
Packit |
9c3e7e |
} while (0);
|
|
Packit |
9c3e7e |
|
|
Packit |
9c3e7e |
/* Rate limited versions */
|
|
Packit |
9c3e7e |
#define pl_emerg(i, x...) PRINT_RL(LOG_EMERG, i, x)
|
|
Packit |
9c3e7e |
#define pl_alert(i, x...) PRINT_RL(LOG_ALERT, i, x)
|
|
Packit |
9c3e7e |
#define pl_crit(i, x...) PRINT_RL(LOG_CRIT, i, x)
|
|
Packit |
9c3e7e |
#define pl_err(i, x...) PRINT_RL(LOG_ERR, i, x)
|
|
Packit |
9c3e7e |
#define pl_warning(i, x...) PRINT_RL(LOG_WARNING, i, x)
|
|
Packit |
9c3e7e |
#define pl_notice(i, x...) PRINT_RL(LOG_NOTICE, i, x)
|
|
Packit |
9c3e7e |
#define pl_info(i, x...) PRINT_RL(LOG_INFO, i, x)
|
|
Packit |
9c3e7e |
#define pl_debug(i, x...) PRINT_RL(LOG_DEBUG, i, x)
|
|
Packit |
9c3e7e |
|
|
Packit |
9c3e7e |
#endif
|