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 /****************************************************************************
3  ** lirc_log.h **************************************************************
4  ****************************************************************************
5  *
6  */
7 
16 #ifndef _LIRC_LOG_H
17 #define _LIRC_LOG_H
18 
19 #include <syslog.h>
20 #include <sys/time.h>
21 #include <stdio.h>
22 #include <unistd.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
37 typedef enum {
38  LIRC_TRACE2 = 10,
39  LIRC_TRACE1 = 9,
40  LIRC_TRACE = 8,
41  LIRC_DEBUG = LOG_DEBUG,
42  LIRC_INFO = LOG_INFO,
43  LIRC_NOTICE = LOG_NOTICE,
44  LIRC_WARNING = LOG_WARNING,
45  LIRC_ERROR = LOG_ERR,
46  LIRC_NOLOG = 0,
47  LIRC_BADLEVEL = -1
48 } loglevel_t;
49 
51 #define LIRC_MAX_LOGLEVEL LIRC_TRACE2
52 
54 #define LIRC_MIN_LOGLEVEL LIRC_ERROR
55 
57 extern loglevel_t loglevel;
58 
59 /* Set by lirc_log_open, convenience copy for clients. */
60 extern char progname[128];
61 
63 #define DEFAULT_LOGLEVEL LIRC_INFO
64 
66 #ifdef __cplusplus
67 #define logmax(l) (l > LIRC_DEBUG ? LIRC_DEBUG : static_cast<loglevel_t>(l) )
68 #else
69 #define logmax(l) (l > LIRC_DEBUG ? LIRC_DEBUG : l )
70 #endif
71 
76 #define LOGPRINTF(level,fmt,args...) \
77  if (level + 7 <= loglevel ) logprintf(logmax(level + 7), fmt, ## args)
78 
83 #define LOGPERROR(level,s) \
84  if (level + 7 <= loglevel ) logperror(logmax(level + 7), s)
85 
86 
87 
92 loglevel_t string2loglevel(const char* level);
93 
95 int lirc_log_setlevel(loglevel_t level);
96 
99 
101 #define lirc_log_is_enabled_for(level) (level <= loglevel)
102 
104 int lirc_log_use_syslog();
105 
112 void logprintf(loglevel_t prio, const char *format_str, ...);
113 
115 void logperror(loglevel_t prio, const char *format, ...);
116 int lirc_log_reopen(void);
117 
127 int lirc_log_open(const char* progname, int _nodaemon, loglevel_t level);
128 
130 int lirc_log_close();
131 
136 void lirc_log_set_file(const char* s);
137 
146 int lirc_log_get_clientlog(const char* basename, char* buffer, ssize_t size);
147 
149 void hexdump(char* prefix, unsigned char* buf, int len);
150 
152 #define STRINGIFY(x) #x
153 
155 #define STR(x) STRINGIFY(x)
156 
158 #define chk_write(fd, buf, count) \
159  do_chk_write(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))
160 
161 
163 #define chk_read(fd, buf, count) \
164  do_chk_read(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))
165 
166 
168 static inline void
169 do_chk_write(int fd, const void *buf, size_t count, const char* msg)
170 {
171  if (write(fd, buf, count) == -1) {
172  logperror(LIRC_WARNING, msg);
173  }
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 
187 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif /* _LIRC_LOG_H */
loglevel_t string2loglevel(const char *level)
Definition: lirc_log.c:219
loglevel_t loglevel
Definition: lirc_log.c:52
int lirc_log_use_syslog()
Definition: lirc_log.c:79
void lirc_log_set_file(const char *s)
Definition: lirc_log.c:85
loglevel_t
Definition: lirc_log.h:37
void hexdump(char *prefix, unsigned char *buf, int len)
Definition: lirc_log.c:332
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:245
int lirc_log_open(const char *progname, int _nodaemon, loglevel_t level)
Definition: lirc_log.c:96
loglevel_t lirc_log_defaultlevel(void)
Definition: lirc_log.c:204
int lirc_log_get_clientlog(const char *basename, char *buffer, ssize_t size)
Definition: lirc_log.c:311
void logperror(loglevel_t prio, const char *format,...)
Definition: lirc_log.c:288
int lirc_log_setlevel(loglevel_t level)
Definition: lirc_log.c:164
int lirc_log_close()
Definition: lirc_log.c:122