Log

From Sharpfin

Jump to: navigation, search

Contents

[edit] Overview

The Libreciva log function provides a support function to store and output log messages.

In order to use the library function, you must include the header file:

#include "log.h"

[edit] void log_init(char *progname, enum log_to dest, enum log_level, int colour)

This function must be called to initialise the log system. The parameters are as follows:

[edit] char *progname

This is the name of the program.

[edit] enum log_to dest

This is the destination of the logger - it is either:

  • LOG_TO_STDERR
  • LOG_TO_SYSLOG

[edit] enum log_level

This is the level of logging to report, it is one of the following:

  • LG_FTL
  • LG_ERR
  • LG_WRN
  • LG_INF
  • LG_DBG

[edit] void logf(enum log_level level, char *format, ...)

This function adds a log entry to the logfile. The level is one of:

  • LG_FTL
  • LG_ERR
  • LG_WRN
  • LG_INF
  • LG_DBG

And the "format, ..." arguments are printf-compatible format string and arguments.

[edit] void log_hexdump(char *txt, unsigned char *data, int len)

This function dumps len bytes of data to the logfile, with a title of txt

[edit] Example

#include "log.h"

main()
{
  int x=2 ;
  log_init("testprog", LOG_TO_STDERR, LG_ERR, 0) ;
  logf(LG_ERR, "This is an error message, x=%d", x) ;
  logf(LG_WRN, "This will not be output as the log_init level is LG_ERR) ;
  logf(LG_FTL, "This log entry will cause a program exit") ;
}
Personal tools