LIRC libraries
LinuxInfraredRemoteControl
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
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
24 extern "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 
50 #define LIRC_MAX_LOGLEVEL LIRC_TRACE2
51 
53 #define LIRC_MIN_LOGLEVEL LIRC_ERROR
54 
56 extern loglevel_t loglevel;
57 
58 /* Set by lirc_log_open, convenience copy for clients. */
59 extern char progname[128];
60 
62 #define DEFAULT_LOGLEVEL LIRC_INFO
63 
65 #ifdef __cplusplus
66 #define logmax(l) (l > LIRC_DEBUG ? LIRC_DEBUG : static_cast <loglevel_t>(l))
67 #else
68 #define logmax(l) (l > LIRC_DEBUG ? LIRC_DEBUG : l)
69 #endif
70 
75 #define LOGPRINTF(level, fmt, args ...) \
76  if (level + 7 <= loglevel) \
77  logprintf(logmax(level + 7), fmt, ## args)
78 
83 #define LOGPERROR(level, s) \
84  if (level + 7 <= loglevel) \
85  logperror(logmax(level + 7), s)
86 
87 
88 
93 loglevel_t string2loglevel(const char* level);
94 
96 int lirc_log_setlevel(loglevel_t level);
97 
100 
102 #define lirc_log_is_enabled_for(level) (level <= loglevel)
103 
105 int lirc_log_use_syslog(void);
106 
113 void logprintf(loglevel_t prio, const char* format_str, ...);
114 
116 void logperror(loglevel_t prio, const char* format, ...);
117 int lirc_log_reopen(void);
118 
128 int lirc_log_open(const char* progname, int _nodaemon, loglevel_t level);
129 
131 int lirc_log_close(void);
132 
137 void lirc_log_set_file(const char* s);
138 
147 int lirc_log_get_clientlog(const char* basename, char* buffer, ssize_t size);
148 
150 void hexdump(char* prefix, unsigned char* buf, int len);
151 
153 #define STRINGIFY(x) #x
154 
156 #define STR(x) STRINGIFY(x)
157 
159 #define chk_write(fd, buf, count) \
160  do_chk_write(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))
161 
162 
164 #define chk_read(fd, buf, count) \
165  do_chk_read(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))
166 
167 
169 static inline void
170 do_chk_write(int fd, const void* buf, size_t count, const char* msg)
171 {
172  if (write(fd, buf, count) == -1)
173  logperror(LIRC_WARNING, msg);
174 }
175 
176 
178 static inline void
179 do_chk_read(int fd, void* buf, size_t count, const char* msg)
180 {
181  if (read(fd, buf, count) == -1)
182  logperror(LIRC_WARNING, msg);
183 }
184 
185 
186 
189 #ifdef __cplusplus
190 }
191 #endif
192 
193 #endif /* _LIRC_LOG_H */
loglevel_t string2loglevel(const char *level)
Definition: lirc_log.c:216
loglevel_t loglevel
Definition: lirc_log.c:39
void lirc_log_set_file(const char *s)
Definition: lirc_log.c:74
int lirc_log_use_syslog(void)
Definition: lirc_log.c:68
loglevel_t
Definition: lirc_log.h:36
void hexdump(char *prefix, unsigned char *buf, int len)
Definition: lirc_log.c:339
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:242
int lirc_log_open(const char *progname, int _nodaemon, loglevel_t level)
Definition: lirc_log.c:85
loglevel_t lirc_log_defaultlevel(void)
Definition: lirc_log.c:201
int lirc_log_get_clientlog(const char *basename, char *buffer, ssize_t size)
Definition: lirc_log.c:310
void logperror(loglevel_t prio, const char *format,...)
Definition: lirc_log.c:288
int lirc_log_close(void)
Definition: lirc_log.c:119
int lirc_log_setlevel(loglevel_t level)
Definition: lirc_log.c:161