Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

log.h File Reference


Detailed Description

A logger object will format and write a text message to the associated file descriptor subject to logging constraints/options that can be changed dynamically during runtime. Logger objects may be chained together, when any member of this chain is passed to aw_log() all logger objects in the chain are evaluated. This is especially useful when you want to log different messages to different file descriptors (e.g., All messages to a master log file, errors to an fd that has an SNMP process listening to send traps to a monitoring system, security warnings to an fd that has an active security watchdog running).

Logging constraints are based a notion of a 'level range'. Each logger has a high level and a low level. Any messages with a level within (inclusive) the level range of the logger being evaluated will be logged to the assocated fd.

Logger objects may (optionally) have another logger object (and chain) associated to handle IO errors. If this object is NULL and AW_LOGGER_ERR2SYSLOG or AW_LOGGER_ERR2STDERR are set, then IO error messages will go to syslog and stderr, respectively.

Note: By passing a negative fd and enabling AW_LOGGER_DUP2SYSLOG you get basic syslog logging only (writes are skipped for negative fds with no error generated).

Options are listed in aw_logger_flag_t.

This library is NOT thread safe, however, the aw_log() function IS thread safe.

#include "sys.h"
#include "thread.h"
#include "errors.h"
#include "util.h"

Go to the source code of this file.

Data Structures

struct  aw_logger_params_t
struct  aw_logger_struct

Defines

#define AW_LOGGER_DEFAULT_FLAGS
 Macro with the default flags settings to pass to aw_logger_init().

#define AW_LOGGER_IS_ROTATING(flags)   ( (flags)&(AW_LOGGER_ROTATE_HR | AW_LOGGER_ROTATE_DY | AW_LOGGER_ROTATE_MH) )
 Macro to test if doing rotation.


Typedefs

typedef aw_logger_struct aw_logger_t

Enumerations

enum  aw_logger_flag_t {
  AW_LOGGER_ENABLED = 0x1, AW_LOGGER_CACHEMSG = 0x2, AW_LOGGER_ERR2SYSLOG = 0x4, AW_LOGGER_ERR2STDERR = 0x8,
  AW_LOGGER_PREPEND_DATE = 0x10, AW_LOGGER_DUP2SYSLOG = 0x20, AW_LOGGER_DUP2STDERR = 0x40, AW_LOGGER_APPEND_NEWLINE = 0x80,
  AW_LOGGER_ROTATE_HR = 0x100, AW_LOGGER_ROTATE_DY = 0x200, AW_LOGGER_ROTATE_MH = 0x400, AW_LOGGER_DEDUP = 0x800,
  AW_LOGGER_NBITS
}
 Bit position indicates capability. More...


Functions

int32_t aw_log (aw_logger_t *logger, int32_t level, const char *fmt,...) __attribute__((format(printf
 Write a message on an aw_logger_t.

int32_t aw_logger_clear (aw_logger_t *logger)
 Free any resources allocated and referenced by logger.

void aw_logger_disable (aw_logger_t *logger)
 Unset enable bit, update chain.

void aw_logger_enable (aw_logger_t *logger)
 Set enable bit, update chain.

int32_t aw_logger_init (aw_logger_t *logger, aw_logger_params_t *params)
 Initialize an aw_logger_t.

int32_t aw_logger_link (aw_logger_t *logger, aw_logger_t *chain)
 Link logger into loggin chain, update chain.

void aw_logger_setflags (aw_logger_t *logger, aw_logger_flag_t new_flags)
 Overwrite flags, update chain.

void aw_logger_unlink (aw_logger_t *logger)
 Unlink logger, update chain.


Define Documentation

#define AW_LOGGER_DEFAULT_FLAGS
 

Value:

Macro with the default flags settings to pass to aw_logger_init().

#define AW_LOGGER_IS_ROTATING (  flags   )     ( (flags)&(AW_LOGGER_ROTATE_HR | AW_LOGGER_ROTATE_DY | AW_LOGGER_ROTATE_MH) )
 

Macro to test if doing rotation.


Typedef Documentation

typedef struct aw_logger_struct aw_logger_t
 


Enumeration Type Documentation

enum aw_logger_flag_t
 

Bit position indicates capability.

Enumeration values:
AW_LOGGER_ENABLED 
AW_LOGGER_CACHEMSG 
AW_LOGGER_ERR2SYSLOG 
AW_LOGGER_ERR2STDERR 
AW_LOGGER_PREPEND_DATE 
AW_LOGGER_DUP2SYSLOG 
AW_LOGGER_DUP2STDERR 
AW_LOGGER_APPEND_NEWLINE 
AW_LOGGER_ROTATE_HR 
AW_LOGGER_ROTATE_DY 
AW_LOGGER_ROTATE_MH 
AW_LOGGER_DEDUP 
AW_LOGGER_NBITS 


Function Documentation

int32_t aw_log (  aw_logger_t *  logger,
int32_t  level,
const char *  fmt,
... 
) 
 

Write a message on an aw_logger_t.

aw_log

Parameters:
logger The logger object (may be NULL, in which case this is a noop)
level Level of log message
fmt Format string (see fprintf)
... Argument list for format string (ala fprintf)
Returns:
Returns 0 on success, AW_LOGWRITE_ERROR,AW_OUTOFMEMORY_ERROR on error

int32_t aw_logger_clear (  aw_logger_t *  logger  ) 
 

Free any resources allocated and referenced by logger.

aw_logger_clear

Parameters:
logger The logger object
Returns:
Returns 0

void aw_logger_disable (  aw_logger_t *  logger  ) 
 

Unset enable bit, update chain.

aw_logger_disable

Parameters:
logger Logger to disable

void aw_logger_enable (  aw_logger_t *  logger  ) 
 

Set enable bit, update chain.

aw_logger_enable

Parameters:
logger Logger to enable

int32_t aw_logger_init (  aw_logger_t *  logger,
aw_logger_params_t *  params
) 
 

Initialize an aw_logger_t.

aw_logger_init

Parameters:
logger The logger object
params The params
Returns:
Returns 0

int32_t aw_logger_link (  aw_logger_t *  logger,
aw_logger_t *  chain
) 
 

Link logger into loggin chain, update chain.

aw_logger_link

Parameters:
logger Logger to link
chain Chain of loggers (can be NULL)
Returns:
Return 0 on success, AW_LOGGER_CHAIN_INSERT_ERROR on failure

void aw_logger_setflags (  aw_logger_t *  logger,
aw_logger_flag_t  new_flags
) 
 

Overwrite flags, update chain.

aw_logger_setflags

Parameters:
logger Logger to set
new_flags New flags for logger

void aw_logger_unlink (  aw_logger_t *  logger  ) 
 

Unlink logger, update chain.

aw_logger_unlink

Parameters:
logger Logger to unlink

Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)