LIRC libraries: /tmp/work/src/lirc-0.10.2/lib/lirc_log.h Source File

LIRC libraries Linux Infrared Remote Control

Loading...
Searching...
No Matches
lirc_log.h
Go to the documentation of this file.
1/****************************************************************************
2** lirc_log.h **************************************************************
3****************************************************************************
4*
5*/
6
15#ifndef _LIRC_LOG_H
16#define _LIRC_LOG_H
17
18#include <syslog.h>
19#include <sys/time.h>
20#include <stdio.h>
21#include <unistd.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
36 typedef enum {
37 LIRC_TRACE2 = 10,
38 LIRC_TRACE1 = 9,
39 LIRC_TRACE = 8,
40 LIRC_DEBUG = LOG_DEBUG,
41 LIRC_INFO = LOG_INFO,
42 LIRC_NOTICE = LOG_NOTICE,
43 LIRC_WARNING = LOG_WARNING,
44 LIRC_ERROR = LOG_ERR,
45 LIRC_NOLOG = 0,
46 LIRC_BADLEVEL = -1
47} loglevel_t;
48
53 typedef enum {
54 LOG_DRIVER = 1,
55 LOG_LIB = 4,
56 LOG_APP = 8,
57 LOG_ALL = 255
58} logchannel_t;
59
61#define LIRC_MAX_LOGLEVEL LIRC_TRACE2
62
64#define LIRC_MIN_LOGLEVEL LIRC_ERROR
65
67void perrorf(const char* format, ...);
68
70extern loglevel_t loglevel;
71
73extern logchannel_t logged_channels;
74
75/* Set by lirc_log_open, convenience copy for clients. */
76extern char progname[128];
77
79#define DEFAULT_LOGLEVEL LIRC_INFO
80
82#ifdef __cplusplus
83#define logmax(l) (l > LIRC_DEBUG ? LIRC_DEBUG : static_cast <loglevel_t>(l))
84#else
85#define logmax(l) (l > LIRC_DEBUG ? LIRC_DEBUG : l)
86#endif
87
89#define log_perror_err(fmt, ...) \
90 { if ((logchannel & logged_channels) && LIRC_ERROR <= loglevel) \
91 { logperror(LIRC_ERROR, fmt, ##__VA_ARGS__); } }
92
94#define log_perror_warn(fmt, ...) \
95 { if ((logchannel & logged_channels) && LIRC_WARNING <= loglevel) \
96 { logperror(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
97
99#define log_perror_debug(fmt, ...) \
100 { if ((logchannel & logged_channels) && LIRC_DEBUG <= loglevel) \
101 { logperror(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
102
104#define log_error(fmt, ...) \
105 { if ((logchannel & logged_channels) && LIRC_ERROR <= loglevel) \
106 { logprintf(LIRC_ERROR, fmt, ##__VA_ARGS__); } }
107
109#define log_warn(fmt, ...) \
110 { if ((logchannel & logged_channels) && LIRC_WARNING <= loglevel) \
111 { logprintf(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
112
114#define log_info(fmt, ...) \
115 { if ((logchannel & logged_channels) && LIRC_INFO <= loglevel) \
116 { logprintf(LIRC_INFO, fmt, ##__VA_ARGS__); } }
117
119#define log_notice(fmt, ...) \
120 { if ((logchannel & logged_channels) && LIRC_NOTICE <= loglevel) \
121 { logprintf(LIRC_NOTICE, fmt, ##__VA_ARGS__); } }
122
124#define log_debug(fmt, ...) \
125 { if ((logchannel & logged_channels) && LIRC_DEBUG <= loglevel) \
126 { logprintf(LIRC_DEBUG, fmt, ##__VA_ARGS__); } }
127
129#define log_trace(fmt, ...) \
130 { if ((logchannel & logged_channels) && LIRC_TRACE <= loglevel) \
131 { logprintf(LIRC_TRACE, fmt, ##__VA_ARGS__); } }
132
134#define log_trace1(fmt, ...) \
135 { if ((logchannel & logged_channels) && LIRC_TRACE1 <= loglevel) \
136 { logprintf(LIRC_TRACE1, fmt, ##__VA_ARGS__); } }
137
139#define log_trace2(fmt, ...) \
140 { if ((logchannel & logged_channels) && LIRC_TRACE2 <= loglevel) \
141 { logprintf(LIRC_TRACE2, fmt, ##__VA_ARGS__); } }
142
143
148 loglevel_t string2loglevel(const char* level);
149
151int lirc_log_setlevel(loglevel_t level);
152
154 loglevel_t lirc_log_defaultlevel(void);
155
157#define lirc_log_is_enabled_for(level) (level <= loglevel)
158
160int lirc_log_use_syslog(void);
161
169void logprintf(loglevel_t prio, const char* format_str, ...);
170
172void logperror(loglevel_t prio, const char* format, ...);
173int lirc_log_reopen(void);
174
184int lirc_log_open(const char* progname, int _nodaemon, loglevel_t level);
185
187int lirc_log_close(void);
188
193void lirc_log_set_file(const char* s);
194
203int lirc_log_get_clientlog(const char* basename, char* buffer, ssize_t size);
204
206void hexdump(char* prefix, unsigned char* buf, int len);
207
209#define STRINGIFY(x) #x
210
212#define STR(x) STRINGIFY(x)
213
215#define chk_write(fd, buf, count) \
216 do_chk_write(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))
217
218
220#define chk_read(fd, buf, count) \
221 do_chk_read(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))
222
223
225static inline void
226do_chk_write(int fd, const void* buf, size_t count, const char* msg)
227{
228 if (write(fd, buf, count) == -1)
229 logperror(LIRC_WARNING, msg);
230}
231
232
234static inline void
235do_chk_read(int fd, void* buf, size_t count, const char* msg)
236{
237 if (read(fd, buf, count) == -1)
238 logperror(LIRC_WARNING, msg);
239}
240
241
242
245#ifdef __cplusplus
246}
247#endif
248
249#endif /* _LIRC_LOG_H */
loglevel
loglevel_t loglevel
The actual loglevel.
Definition lirc_log.c:47
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
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
logged_channels
logchannel_t logged_channels
The actual logchannel.
Definition lirc_log.c:49
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