lirc_log.h File Reference
Internal API | User-space driver API

### (6bfe0ff 2016-04-26 15:59:19 +0200)

Logging functionality. More...

`#include <syslog.h>`
`#include <sys/time.h>`
`#include <stdio.h>`
`#include <unistd.h>`

Go to the source code of this file.

## Macros

#define | LIRC_MAX_LOGLEVEL LIRC_TRACE2
#define | LIRC_MIN_LOGLEVEL LIRC_ERROR
#define | DEFAULT_LOGLEVEL LIRC_INFO
#define | logmax(l) (l > LIRC_DEBUG ? LIRC_DEBUG : l)
#define | log_perror_err(fmt, ...)
#define | log_perror_warn(fmt, ...)
#define | log_perror_debug(fmt, ...)
#define | log_error(fmt, ...)
#define | log_warn(fmt, ...)
#define | log_info(fmt, ...)
#define | log_notice(fmt, ...)
#define | log_debug(fmt, ...)
#define | log_trace(fmt, ...)
#define | log_trace1(fmt, ...)
#define | log_trace2(fmt, ...)
#define | lirc_log_is_enabled_for(level) (level <= loglevel)
#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__))

## Enumerations

enum | loglevel_t { 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 }
enum | logchannel_t { LOG_DRIVER = 1, LOG_LIB = 4, LOG_APP = 8, LOG_ALL = 255 }

## Functions

void | perrorf (const char *format,...)
loglevel_t | string2loglevel (const char *level)
int | lirc_log_setlevel (loglevel_t level)
loglevel_t | lirc_log_defaultlevel (void)
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)

## Variables

loglevel_t | loglevel
logchannel_t | logged_channels
char | progname [128]

## Detailed Description

Logging functionality.

Definition in file lirc_log.h.

## Macro Definition Documentation

## chk_read

#define chk_read | ( |  | fd,
|  |  | buf,
|  |  | count
| ) |  | do_chk_read(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))

Wrapper for read(2) which logs errors.

Definition at line 220 of file lirc_log.h.

## chk_write

#define chk_write | ( |  | fd,
|  |  | buf,
|  |  | count
| ) |  | do_chk_write(fd, buf, count, STR(__FILE__) ":" STR(__LINE__))

Wrapper for write(2) which logs errors.

Definition at line 215 of file lirc_log.h.

## DEFAULT_LOGLEVEL

#define DEFAULT_LOGLEVEL LIRC_INFO

Default loglevel (last resort).

Definition at line 79 of file lirc_log.h.

## lirc_log_is_enabled_for

#define lirc_log_is_enabled_for | ( |  | level | ) | (level <= loglevel)

Check if a given, standard loglevel should be printed.

Definition at line 157 of file lirc_log.h.

## LIRC_MAX_LOGLEVEL

#define LIRC_MAX_LOGLEVEL LIRC_TRACE2

Max loglevel (for validation).

Definition at line 61 of file lirc_log.h.

## LIRC_MIN_LOGLEVEL

#define LIRC_MIN_LOGLEVEL LIRC_ERROR

Mix loglevel (for validation).

Definition at line 64 of file lirc_log.h.

## log_debug

#define log_debug | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_DEBUG <= loglevel) \
{ logprintf(LIRC_DEBUG, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logprintf
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:272
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

Log a debug message.

Examples:
  irexec.cpp.

Definition at line 124 of file lirc_log.h.

## log_error

#define log_error | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_ERROR <= loglevel) \
{ logprintf(LIRC_ERROR, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logprintf
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:272
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

Log an error message.

Definition at line 104 of file lirc_log.h.

## log_info

#define log_info | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_INFO <= loglevel) \
{ logprintf(LIRC_INFO, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logprintf
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:272
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

Log an info message.

Definition at line 114 of file lirc_log.h.

## log_notice

#define log_notice | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_NOTICE <= loglevel) \
{ logprintf(LIRC_NOTICE, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logprintf
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:272
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

Log a notice message.

Definition at line 119 of file lirc_log.h.

## log_perror_debug

#define log_perror_debug | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_DEBUG <= loglevel) \
{ logperror(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logperror
void logperror(loglevel_t prio, const char *format,...)
Definition: lirc_log.c:318
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

perror wrapper logging with level LIRC_DEBUG.

Definition at line 99 of file lirc_log.h.

## log_perror_err

#define log_perror_err | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_ERROR <= loglevel) \
{ logperror(LIRC_ERROR, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logperror
void logperror(loglevel_t prio, const char *format,...)
Definition: lirc_log.c:318
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

perror wrapper logging with level LIRC_ERROR.

Examples:
  irexec.cpp.

Definition at line 89 of file lirc_log.h.

## log_perror_warn

#define log_perror_warn | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_WARNING <= loglevel) \
{ logperror(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logperror
void logperror(loglevel_t prio, const char *format,...)
Definition: lirc_log.c:318
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

perror wrapper logging with level LIRC_WARNING.

Definition at line 94 of file lirc_log.h.

## log_trace

#define log_trace | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_TRACE <= loglevel) \
{ logprintf(LIRC_TRACE, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logprintf
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:272
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

Log a trace message.

Definition at line 129 of file lirc_log.h.

## log_trace1

#define log_trace1 | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_TRACE1 <= loglevel) \
{ logprintf(LIRC_TRACE1, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logprintf
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:272
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

Log a trace1 message.

Definition at line 134 of file lirc_log.h.

## log_trace2

#define log_trace2 | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_TRACE2 <= loglevel) \
{ logprintf(LIRC_TRACE2, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logprintf
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:272
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

Log a trace2 message.

Definition at line 139 of file lirc_log.h.

## log_warn

#define log_warn | ( |  | fmt,
|  |  | ...
| ) |  |

Value:
{ if ((logchannel & logged_channels) && LIRC_WARNING <= loglevel) \
{ logprintf(LIRC_WARNING, fmt, ##__VA_ARGS__); } }
loglevel
loglevel_t loglevel
Definition: lirc_log.c:47
logprintf
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:272
logged_channels
logchannel_t logged_channels
Definition: lirc_log.c:49

Log a warning message.

Definition at line 109 of file lirc_log.h.

## logmax

#define logmax | ( |  | l | ) | (l > LIRC_DEBUG ? LIRC_DEBUG : l)

Max level logged in actual logfile.

Definition at line 85 of file lirc_log.h.

## STR

#define STR | ( |  | x | ) | STRINGIFY(x)

Return x in (double) quotes.

Definition at line 212 of file lirc_log.h.

## STRINGIFY

#define STRINGIFY | ( |  | x | ) | #x

Helper macro for STR().

Definition at line 209 of file lirc_log.h.

## Enumeration Type Documentation

## logchannel_t

enum logchannel_t

Log channels used to filter messages.

Definition at line 53 of file lirc_log.h.

## loglevel_t

enum loglevel_t

The defined loglevels. LIRC_TRACE..LIRC_TRACE2 is mapped to LIRC_DEBUG in outputted messages, but generates more messages than DEBUG.

Definition at line 36 of file lirc_log.h.

## Function Documentation

## hexdump()

void hexdump | ( | char * | prefix,
|  | unsigned char * | buf,
|  | int | len
| ) |  |

Print prefix + a hex dump of len bytes starting at *buf.

Definition at line 377 of file lirc_log.c.

## lirc_log_close()

int lirc_log_close | ( | void |  | ) |

Close the log previosly opened with lirc_log_open().

Definition at line 136 of file lirc_log.c.

## lirc_log_defaultlevel()

loglevel_t lirc_log_defaultlevel | ( | void |  | ) |

Get the default level, from environment or hardcoded.

Definition at line 218 of file lirc_log.c.

## 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.

Parameters

  basename | Basename for the logfile.
  buff | Buffer to store result in.
  size | Size of buffer

Returns
  0 if OK, otherwise -1

Definition at line 340 of file lirc_log.c.

## lirc_log_open()

int lirc_log_open | ( | const char * | progname,
|  | int | _nodaemon,
|  | loglevel_t | level
| ) |  |

Open the log for upcoming logging

Parameters

  progname | Name of application, made available in global progname
  nodaemon | If true, program runs in foreground and logging is on also on stdout.
  level | The lowest level of messages to actually be logged.

Returns
  0 if OK, else positive error code.

Definition at line 95 of file lirc_log.c.

## lirc_log_set_file()

void lirc_log_set_file | ( | const char * | s | ) |

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().

Definition at line 84 of file lirc_log.c.

## lirc_log_setlevel()

int lirc_log_setlevel | ( | loglevel_t | level | ) |

Set the level. Returns 1 if ok, 0 on errors.

Definition at line 178 of file lirc_log.c.

## lirc_log_use_syslog()

int lirc_log_use_syslog | ( | void |  | ) |

Check if log is set up to use syslog or not.

Definition at line 78 of file lirc_log.c.

## logperror()

void logperror | ( | loglevel_t | prio,
|  | const char * | fmt,
|  |  | ...
| ) |  |

Log current kernel error with a given level.

Prints a description of the last error to the log.

Parameters

  prio | Priority of log request.
  fmt | printf-style format string

Definition at line 318 of file lirc_log.c.

## logprintf()

void logprintf | ( | loglevel_t | prio,
|  | const char * | format_str,
|  |  | ...
| ) |  |

Write a message to the log. Caller should use the log_ macros and not call this directly.

Parameters

  prio | Level of message
  format_str,... | printf-style string.

Write a message to the log. Caller should use the log_ macros and not call this directly.

Parameters

  prio | Priority of log request
  format_str | Format string in the usual C sense.
  ... | Additional vararg parameters.

Definition at line 272 of file lirc_log.c.

## perrorf()

void perrorf | ( | const char * | format,
|  |  | ...
| ) |  |

Adds printf-style arguments to perror(3).

Definition at line 253 of file lirc_log.c.

## string2loglevel()

loglevel_t string2loglevel | ( | const char * | level | ) |

Convert a string, either a number or 'info', 'trace1', error etc. to a loglevel.

Definition at line 233 of file lirc_log.c.

## Variable Documentation

## logged_channels

logchannel_t logged_channels

The actual logchannel. Should not be changed directly by external code.

Definition at line 49 of file lirc_log.c.

## loglevel

loglevel_t loglevel

The actual loglevel. Should not be changed directly by external code.

Definition at line 47 of file lirc_log.c.