Loading...
Searching...
No Matches
lirc_log.c File Reference

Implements lirc_log.h. More...

`#include <errno.h>`
`#include <stdarg.h>`
`#include <stdlib.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include <sys/stat.h>`
`#include <time.h>`
`#include <pwd.h>`
`#include <unistd.h>`
`#include <limits.h>`
`#include <ctype.h>`
`#include <syslog.h>`
`#include "lirc/lirc_log.h"`

Go to the source code of this file.

## Macros

#define | min(a, b) (a < b ? a : b)
#define | HOSTNAME_LEN 128

## Functions

int | lirc_log_use_syslog (void)
| Check if log is set up to use syslog or not.
void | lirc_log_set_file (const char *s)
| Set logfile.
int | lirc_log_open (const char *_progname, int _nodaemon, loglevel_t level)
| Open the log for upcoming logging.
int | lirc_log_close (void)
| Close the log previosly opened with lirc_log_open().
int | lirc_log_reopen (void)
int | lirc_log_setlevel (loglevel_t level)
| Set the level.
loglevel_t | lirc_log_defaultlevel (void)
| Get the default level, from environment or hardcoded.
loglevel_t | string2loglevel (const char *s)
| Convert a string, either a number or 'info', 'trace1', error etc.
void | perrorf (const char *format,...)
| Adds printf-style arguments to perror(3).
void | logprintf (loglevel_t prio, const char *format_str,...)
| Write a message to the log.
void | logperror (loglevel_t prio, const char *fmt,...)
| Prints a description of the last error to the log.
int | lirc_log_get_clientlog (const char *basename, char *buffer, ssize_t size)
| Retrieve a client path for logging according to freedesktop specs.
void | hexdump (char *prefix, unsigned char *buf, int len)
| Print prefix + a hex dump of len bytes starting at *buf.

## Variables

char | hostname [HOSTNAME_LEN+1]
FILE * | lf = NULL
loglevel_t | loglevel = LIRC_NOLOG
| The actual loglevel.
logchannel_t | logged_channels = LOG_ALL
| The actual logchannel.
const char * | syslogident = "lircd-" VERSION
const char * | logfile = "syslog"
char | progname [128] = { '?', '\0' }

## Detailed Description

Implements lirc_log.h.

Author
  Ralph Metzler, Christoph Bartelmus

Definition in file lirc_log.c.

## Macro Definition Documentation

## HOSTNAME_LEN

#define HOSTNAME_LEN 128

Definition at line 40 of file lirc_log.c.

## min

#define min | ( |  | a,
|  |  | b
| ) |  | (a < b ? a : b)

Definition at line 37 of file lirc_log.c.

## 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 369 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 137 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 219 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 332 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_reopen()

int lirc_log_reopen | ( | void |  | ) |

Definition at line 150 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 179 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,
|  |  | ...
| ) |  |

Prints a description of the last error to the log.

Log current kernel error with a given level.

Parameters

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

Definition at line 310 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 | Priority of log request
  format_str | Format string in the usual C sense.
  ... | Additional vararg parameters.

Definition at line 273 of file lirc_log.c.

## perrorf()

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

Adds printf-style arguments to perror(3).

Definition at line 254 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 234 of file lirc_log.c.

## Variable Documentation

## hostname

char hostname[HOSTNAME_LEN+1]

Definition at line 44 of file lirc_log.c.

## lf

FILE* lf = NULL

Definition at line 45 of file lirc_log.c.

## logfile

const char* logfile = "syslog"

Definition at line 54 of file lirc_log.c.

## logged_channels

logchannel_t logged_channels = LOG_ALL

The actual logchannel.

Should not be changed directly by external code.

Definition at line 49 of file lirc_log.c.

## loglevel

loglevel_t loglevel = LIRC_NOLOG

The actual loglevel.

Should not be changed directly by external code.

Definition at line 47 of file lirc_log.c.

## progname

char progname[128] = { '?', '\0' }

Definition at line 56 of file lirc_log.c.

## syslogident

const char* syslogident = "lircd-" VERSION

Definition at line 53 of file lirc_log.c.