LIRC libraries LinuxInfraredRemoteControl

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

Macros | Enumerations | Functions | Variables
lirc_log.h File Reference
Internal API | User-space driver API

### (dad0c0a 2015-02-09 13:36:06 +0100)

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 | LOGPRINTF(level, fmt, args...)
#define | LOGPERROR(level, s)
#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 }

## Functions
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
char | progname [128]

## Detailed Description

Logging functionality.

Definition in file lirc_log.h.

## Macro Definition Documentation

#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 164 of file lirc_log.h.

#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 159 of file lirc_log.h.

#define DEFAULT_LOGLEVEL LIRC_INFO

Default loglevel (last resort).

Definition at line 62 of file lirc_log.h.

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

Check if a given, standard loglevel should be printed.

Definition at line 102 of file lirc_log.h.

#define LIRC_MAX_LOGLEVEL LIRC_TRACE2

Max loglevel (for validation).

Definition at line 50 of file lirc_log.h.

#define LIRC_MIN_LOGLEVEL LIRC_ERROR

Mix loglevel (for validation).

Definition at line 53 of file lirc_log.h.

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

Max level logged in actual logfile.

Definition at line 68 of file lirc_log.h.

#define LOGPERROR | ( |  | level,
|  |  | s
| ) |  |

Value:
if (level + 7 <= loglevel) \
logperror(logmax(level + 7), s)
loglevel
loglevel_t loglevel
Definition: lirc_log.c:40
logperror
void logperror(loglevel_t prio, const char *format,...)
Definition: lirc_log.c:289
logmax
#define logmax(l)
Definition: lirc_log.h:68

Compatibility perror(3) wrapper Accepts level 1..3 which are mapped to LIRC_TRACE..LIRC_TRACE2.

Definition at line 83 of file lirc_log.h.

#define LOGPRINTF | ( |  | level,
|  |  | fmt,
|  |  | args...
| ) |  |

Value:
if (level + 7 <= loglevel) \
logprintf(logmax(level + 7), fmt, ## args)
loglevel
loglevel_t loglevel
Definition: lirc_log.c:40
logprintf
void logprintf(loglevel_t prio, const char *format_str,...)
Definition: lirc_log.c:243
logmax
#define logmax(l)
Definition: lirc_log.h:68

Compatibility log message stuff.. Accepts level 1..3 which are mapped to LIRC_TRACE..LIRC_TRACE2.

Definition at line 75 of file lirc_log.h.

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

Return x in (double) quotes.

Definition at line 156 of file lirc_log.h.

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

Helper macro for STR().

Definition at line 153 of file lirc_log.h.

## Enumeration Type Documentation

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

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

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

Definition at line 348 of file lirc_log.c.

int lirc_log_close | ( | void |  | ) |

Close the log previosly opened with lirc_log_open().

Definition at line 120 of file lirc_log.c.

loglevel_t lirc_log_defaultlevel | ( | void |  | ) |

Get the default level, from environment or hardcoded.

Definition at line 202 of file lirc_log.c.

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 311 of file lirc_log.c.

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 86 of file lirc_log.c.

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 75 of file lirc_log.c.

int lirc_log_setlevel | ( | loglevel_t | level | ) |

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

Definition at line 162 of file lirc_log.c.

int lirc_log_use_syslog | ( | void |  | ) |

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

Definition at line 69 of file lirc_log.c.

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 289 of file lirc_log.c.

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

Write a message to log.

Parameters

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

Prints the log request to the log, if the priority fits.

Parameters

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

Definition at line 243 of file lirc_log.c.

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

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

Definition at line 217 of file lirc_log.c.

## Variable Documentation

loglevel_t loglevel

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

Definition at line 40 of file lirc_log.c.