poser
A C framework for POsix SERvices
Loading...
Searching...
No Matches
PSC_Log Class Reference

A logging mechanism offering pluggable writers. More...

#include <poser/core/log.h>

Static Public Member Functions

void PSC_Log_setFileLogger (FILE *file)
 Use a standard file logger.
 
void PSC_Log_setSyslogLogger (const char *ident, int facility, int withStderr)
 Use a standard syslog loggeer.
 
void PSC_Log_setCustomLogger (PSC_LogWriter writer, void *data)
 Use a custom log writer.
 
void PSC_Log_setMaxLogLevel (PSC_LogLevel level)
 Set maximum log level.
 
void PSC_Log_setSilent (int silent)
 Enable/disable silent mode.
 
void PSC_Log_setAsync (int async)
 Enable/disable asynchronous logging.
 
int PSC_Log_enabled (PSC_LogLevel level)
 Check whether log level is enabled.
 
void PSC_Log_msg (PSC_LogLevel level, const char *message)
 Log a message.
 
void PSC_Log_fmt (PSC_LogLevel level, const char *format,...)
 Log a message using a prinft-like format string.
 

Detailed Description

A logging mechanism offering pluggable writers.

This is a simple logging mechanism that can use any write function to implement different "log sinks". A function writing to an opened FILE and a function writing to syslog are included. It can optionally log asynchronously (making use of PSC_ThreadPool).

By default, no log writer is configured, so any log messages are just dropped. You have to set a log writer if you want to see log messages.

Note that PSC_Service_Run() automatically configures log writers if configured to do so via PSC_RunOpts.

Member Function Documentation

◆ PSC_Log_enabled()

int PSC_Log_enabled ( PSC_LogLevel  level)
static

Check whether log level is enabled.

Checks whether a given log level would currently produce a log message.

Parameters
levelthe log level to check
Returns
1 if the level is enabled, 0 otherwise

◆ PSC_Log_fmt()

void PSC_Log_fmt ( PSC_LogLevel  level,
const char *  format,
  ... 
)
static

Log a message using a prinft-like format string.

Parameters
levelthe log level
formatthe printf-like format string
...optional arguments for conversions in the format string

◆ PSC_Log_msg()

void PSC_Log_msg ( PSC_LogLevel  level,
const char *  message 
)
static

Log a message.

Parameters
levelthe log level
messagethe message

◆ PSC_Log_setAsync()

void PSC_Log_setAsync ( int  async)
static

Enable/disable asynchronous logging.

In asynchronous mode, calling the actual log writer is done on a worker thread, to avoid having to wait for I/O caused by it on the main thread.

Asynchronous mode is disabled by default, but it is recommended to enable it once your service is up and running, as long as you can't guarantee your log writer will never block. Note that both writing to a file (on disk) and writing to syslog can block.

Also note PSC_Service_run() automatically enables asynchronous logging when configured to handle logging via PSC_RunOpts.

Parameters
async1: enable asynchronous mode, 0: disable asynchronous mode

◆ PSC_Log_setCustomLogger()

void PSC_Log_setCustomLogger ( PSC_LogWriter  writer,
void *  data 
)
static

Use a custom log writer.

Parameters
writerthe log writer
dataoptional context data for the writer

◆ PSC_Log_setFileLogger()

void PSC_Log_setFileLogger ( FILE *  file)
static

Use a standard file logger.

Parameters
filethe opened file to write log messages to

◆ PSC_Log_setMaxLogLevel()

void PSC_Log_setMaxLogLevel ( PSC_LogLevel  level)
static

Set maximum log level.

Only log messages up to this level. Highest: PSC_L_DEBUG, lowest: PSC_L_FATAL. Default is PSC_L_INFO.

Parameters
levelthe new maximum log level

◆ PSC_Log_setSilent()

void PSC_Log_setSilent ( int  silent)
static

Enable/disable silent mode.

This can be used to temporarily suppress all messages except PSC_L_FATAL and PSC_L_ERROR, regardless of the maximum log level.

Parameters
silent1: enable silent mode, 0: disable silent mode

◆ PSC_Log_setSyslogLogger()

void PSC_Log_setSyslogLogger ( const char *  ident,
int  facility,
int  withStderr 
)
static

Use a standard syslog loggeer.

Parameters
identthe name to use for syslog (name of your service)
facilitythe syslog facility (e.g. LOG_DAEMON)
withStderr(0) or (1): also write to stderr

The documentation for this class was generated from the following file: