/usr/include/lirc/lirc_log.h is in liblirc-dev 0.9.4c-9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | /****************************************************************************
** lirc_log.h **************************************************************
****************************************************************************
*
*/
/**
* @file lirc_log.h
* @brief Logging functionality.
* @ingroup private_api
* @ingroup driver_api
*/
#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
/**
* @addtogroup driver_api
*/
/**
* The defined loglevels. LIRC_TRACE..LIRC_TRACE2 is mapped to LIRC_DEBUG in
* outputted messages, but generates more messages than DEBUG.
*/
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;
/**
* Log channels used to filter messages.
*/
typedef enum {
LOG_DRIVER = 1,
LOG_LIB = 4,
LOG_APP = 8,
LOG_ALL = 255
} logchannel_t;
/** Max loglevel (for validation). */
#define LIRC_MAX_LOGLEVEL LIRC_TRACE2
/** Mix loglevel (for validation). */
#define LIRC_MIN_LOGLEVEL LIRC_ERROR
/** Adds printf-style arguments to perror(3). */
void perrorf(const char* format, ...);
/** The actual loglevel. Should not be changed directly by external code.*/
extern loglevel_t loglevel;
/** The actual logchannel. Should not be changed directly by external code.*/
extern logchannel_t logged_channels;
/* Set by lirc_log_open, convenience copy for clients. */
extern char progname[128];
/** Default loglevel (last resort). */
#define DEFAULT_LOGLEVEL LIRC_INFO
/** Max level logged in actual logfile. */
#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
/** perror wrapper logging with level LIRC_ERROR. */
#define log_perror_err(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_ERROR <= loglevel) \
{ logperror(LIRC_ERROR, fmt, ##__VA_ARGS__); } }
/** perror wrapper logging with level LIRC_WARNING. */
#define log_perror_warn(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_WARNING <= loglevel) \
{ logperror(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
/** perror wrapper logging with level LIRC_DEBUG. */
#define log_perror_debug(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_DEBUG <= loglevel) \
{ logperror(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
/** Log an error message. */
#define log_error(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_ERROR <= loglevel) \
{ logprintf(LIRC_ERROR, fmt, ##__VA_ARGS__); } }
/** Log a warning message. */
#define log_warn(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_WARNING <= loglevel) \
{ logprintf(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
/** Log an info message. */
#define log_info(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_INFO <= loglevel) \
{ logprintf(LIRC_INFO, fmt, ##__VA_ARGS__); } }
/** Log a notice message. */
#define log_notice(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_NOTICE <= loglevel) \
{ logprintf(LIRC_NOTICE, fmt, ##__VA_ARGS__); } }
/** Log a debug message. */
#define log_debug(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_DEBUG <= loglevel) \
{ logprintf(LIRC_DEBUG, fmt, ##__VA_ARGS__); } }
/** Log a trace message. */
#define log_trace(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_TRACE <= loglevel) \
{ logprintf(LIRC_TRACE, fmt, ##__VA_ARGS__); } }
/** Log a trace1 message. */
#define log_trace1(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_TRACE1 <= loglevel) \
{ logprintf(LIRC_TRACE1, fmt, ##__VA_ARGS__); } }
/** Log a trace2 message. */
#define log_trace2(fmt, ...) \
{ if ((logchannel & logged_channels) && LIRC_TRACE2 <= loglevel) \
{ logprintf(LIRC_TRACE2, fmt, ##__VA_ARGS__); } }
/**
* Convert a string, either a number or 'info', 'trace1', error etc.
* to a loglevel.
*/
loglevel_t string2loglevel(const char* level);
/** Set the level. Returns 1 if ok, 0 on errors. */
int lirc_log_setlevel(loglevel_t level);
/** Get the default level, from environment or hardcoded. */
loglevel_t lirc_log_defaultlevel(void);
/** Check if a given, standard loglevel should be printed. */
#define lirc_log_is_enabled_for(level) (level <= loglevel)
/** Check if log is set up to use syslog or not. */
int lirc_log_use_syslog(void);
/**
* Write a message to the log.
* Caller should use the log_ macros and not call this directly.
*
* @param prio Level of message
* @param format_str,... printf-style string.
*/
void logprintf(loglevel_t prio, const char* format_str, ...);
/** Log current kernel error with a given level. */
void logperror(loglevel_t prio, const char* format, ...);
int lirc_log_reopen(void);
/**
* Open the log for upcoming logging
*
* @param progname Name of application, made available in global progname
* @param nodaemon If true, program runs in foreground and logging is on also
* on stdout.
* @param level The lowest level of messages to actually be logged.
* @return 0 if OK, else positive error code.
*/
int lirc_log_open(const char* progname, int _nodaemon, loglevel_t level);
/** Close the log previosly opened with lirc_log_open(). */
int lirc_log_close(void);
/**
* Set logfile. Either a regular path or the string 'syslog'; the latter
* does indeed use syslog(1) instead. Must be called before lirc_log_open().
*/
void lirc_log_set_file(const char* s);
/**
* Retrieve a client path for logging according to freedesktop specs.
*
* @param basename Basename for the logfile.
* @param buff Buffer to store result in.
* @param size Size of buffer
* @return 0 if OK, otherwise -1
*/
int lirc_log_get_clientlog(const char* basename, char* buffer, ssize_t size);
/** Print prefix + a hex dump of len bytes starting at *buf. */
void hexdump(char* prefix, unsigned char* buf, int len);
/** Helper macro for STR().*/
#define STRINGIFY(x) #x
/** Return x in (double) quotes. */
#define STR(x) STRINGIFY(x)
/** Wrapper for write(2) which logs errors. */
#define chk_write(fd, buf, count) \
do_chk_write(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))
/** Wrapper for read(2) which logs errors. */
#define chk_read(fd, buf, count) \
do_chk_read(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))
/** Implement the chk_write() macro. */
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);
}
/** Implement the chk_read() macro. */
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 */
|