Loading...
Searching...
No Matches
lirc_log.h
Go to the documentation of this file.
/****************************************************************************
** lirc_log.h **************************************************************
****************************************************************************
*
*/
#ifndef _LIRC_LOG_H
#define _LIRC_LOG_H
#include <syslog.h>
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
LIRC_TRACE2 = 10,
LIRC_TRACE1 = 9,
LIRC_TRACE = 8,
LIRC_DEBUG = LOG_DEBUG,
LIRC_INFO = LOG_INFO,
LIRC_NOTICE = LOG_NOTICE,
LIRC_WARNING = LOG_WARNING,
LIRC_ERROR = LOG_ERR,
LIRC_NOLOG = 0,
LIRC_BADLEVEL = -1
} loglevel_t;
typedef enum {
LOG_DRIVER = 1,
LOG_LIB = 4,
LOG_APP = 8,
LOG_ALL = 255
} logchannel_t;
#define LIRC_MAX_LOGLEVEL LIRC_TRACE2
#define LIRC_MIN_LOGLEVEL LIRC_ERROR
void perrorf(const char* format, ...);
extern loglevel_t loglevel;
extern logchannel_t logged_channels;
/* Set by lirc_log_open, convenience copy for clients. */
extern char progname[128];
#define DEFAULT_LOGLEVEL LIRC_INFO
#ifdef __cplusplus
#define logmax(l) (l > LIRC_DEBUG ? LIRC_DEBUG : static_cast <loglevel_t>(l))
#else
#define logmax(l) (l > LIRC_DEBUG ? LIRC_DEBUG : l)
#endif
#define log_perror_err(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_ERROR <= loglevel) \
{ logperror(LIRC_ERROR, fmt, ##__VA_ARGS__); } }
#define log_perror_warn(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_WARNING <= loglevel) \
{ logperror(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
#define log_perror_debug(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_DEBUG <= loglevel) \
{ logperror(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
#define log_error(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_ERROR <= loglevel) \
{ logprintf(LIRC_ERROR, fmt, ##__VA_ARGS__); } }
#define log_warn(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_WARNING <= loglevel) \
{ logprintf(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
#define log_info(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_INFO <= loglevel) \
{ logprintf(LIRC_INFO, fmt, ##__VA_ARGS__); } }
#define log_notice(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_NOTICE <= loglevel) \
{ logprintf(LIRC_NOTICE, fmt, ##__VA_ARGS__); } }
#define log_debug(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_DEBUG <= loglevel) \
{ logprintf(LIRC_DEBUG, fmt, ##__VA_ARGS__); } }
#define log_trace(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_TRACE <= loglevel) \
{ logprintf(LIRC_TRACE, fmt, ##__VA_ARGS__); } }
#define log_trace1(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_TRACE1 <= loglevel) \
{ logprintf(LIRC_TRACE1, fmt, ##__VA_ARGS__); } }
#define log_trace2(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_TRACE2 <= loglevel) \
{ logprintf(LIRC_TRACE2, fmt, ##__VA_ARGS__); } }
loglevel_t string2loglevel(const char* level);
int lirc_log_setlevel(loglevel_t level);
loglevel_t lirc_log_defaultlevel(void);
#define lirc_log_is_enabled_for(level) (level <= loglevel)
int lirc_log_use_syslog(void);
void logprintf(loglevel_t prio, const char* format_str, ...);
void logperror(loglevel_t prio, const char* format, ...);
int lirc_log_reopen(void);
int lirc_log_open(const char* progname, int _nodaemon, loglevel_t level);
int lirc_log_close(void);
void lirc_log_set_file(const char* s);
int lirc_log_get_clientlog(const char* basename, char* buffer, ssize_t size);
void hexdump(char* prefix, unsigned char* buf, int len);
#define STRINGIFY(x) #x
#define STR(x) STRINGIFY(x)
#define chk_write(fd, buf, count) \
do_chk_write(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))
#define chk_read(fd, buf, count) \
do_chk_read(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))
static inline void
do_chk_write(int fd, const void* buf, size_t count, const char* msg)
{
if (write(fd, buf, count) == -1)
logperror(LIRC_WARNING, msg);
}
static inline void
do_chk_read(int fd, void* buf, size_t count, const char* msg)
{
if (read(fd, buf, count) == -1)
logperror(LIRC_WARNING, msg);
}
#ifdef __cplusplus
}
#endif
#endif /* _LIRC_LOG_H */
loglevel
loglevel_t loglevel
The actual loglevel.
Definition lirc_log.c:47
logged_channels
logchannel_t logged_channels
The actual logchannel.
Definition lirc_log.c:49
loglevel_t
loglevel_t
The defined loglevels.
Definition lirc_log.h:36
lirc_log_use_syslog
int lirc_log_use_syslog(void)
Check if log is set up to use syslog or not.
Definition lirc_log.c:78
logprintf
void logprintf(loglevel_t prio, const char *format_str,...)
Write a message to the log.
Definition lirc_log.c:273
lirc_log_set_file
void lirc_log_set_file(const char *s)
Set logfile.
Definition lirc_log.c:84
hexdump
void hexdump(char *prefix, unsigned char *buf, int len)
Print prefix + a hex dump of len bytes starting at *buf.
Definition lirc_log.c:369
lirc_log_setlevel
int lirc_log_setlevel(loglevel_t level)
Set the level.
Definition lirc_log.c:179
lirc_log_get_clientlog
int lirc_log_get_clientlog(const char *basename, char *buffer, ssize_t size)
Retrieve a client path for logging according to freedesktop specs.
Definition lirc_log.c:332
string2loglevel
loglevel_t string2loglevel(const char *level)
Convert a string, either a number or 'info', 'trace1', error etc.
Definition lirc_log.c:234
lirc_log_open
int lirc_log_open(const char *progname, int _nodaemon, loglevel_t level)
Open the log for upcoming logging.
Definition lirc_log.c:95
perrorf
void perrorf(const char *format,...)
Adds printf-style arguments to perror(3).
Definition lirc_log.c:254
logchannel_t
logchannel_t
Log channels used to filter messages.
Definition lirc_log.h:53
lirc_log_close
int lirc_log_close(void)
Close the log previosly opened with lirc_log_open().
Definition lirc_log.c:137
logperror
void logperror(loglevel_t prio, const char *format,...)
Log current kernel error with a given level.
Definition lirc_log.c:310
lirc_log_defaultlevel
loglevel_t lirc_log_defaultlevel(void)
Get the default level, from environment or hardcoded.
Definition lirc_log.c:219