poser
A C framework for POsix SERvices
|
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. | |
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.
|
static |
Check whether log level is enabled.
Checks whether a given log level would currently produce a log message.
level | the log level to check |
|
static |
Log a message using a prinft-like format string.
level | the log level |
format | the printf-like format string |
... | optional arguments for conversions in the format string |
|
static |
Log a message.
level | the log level |
message | the message |
|
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.
async | 1: enable asynchronous mode, 0: disable asynchronous mode |
|
static |
Use a custom log writer.
writer | the log writer |
data | optional context data for the writer |
|
static |
Use a standard file logger.
file | the opened file to write log messages to |
|
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.
level | the new maximum log level |
|
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.
silent | 1: enable silent mode, 0: disable silent mode |
|
static |
Use a standard syslog loggeer.
ident | the name to use for syslog (name of your service) |
facility | the syslog facility (e.g. LOG_DAEMON) |
withStderr | (0) or (1): also write to stderr |