libgslutil  1.2.3
Data Structures | Macros | Enumerations | Functions

Data Structures

struct  log_ratelimit_t
 Rate-limiting log details. More...
 

Macros

#define LOG(level, fmt, ...)
 Log to syslog. More...
 
#define LOG_RATE(rate, level, fmt, ...)
 Rate-limited logging. More...
 
#define LOG_HEXDUMP(data, len, desc, ...)
 Debug support: log hexdump. More...
 

Enumerations

enum  gslutil_log_destination_t { gslutil_log_destination_syslog, gslutil_log_destination_stderr, gslutil_log_destination_none }
 Possible log destinations. More...
 

Functions

void gslutil_log_destination (enum gslutil_log_destination_t dest)
 Change log destination. More...
 
enum gslutil_log_destination_t gslutil_get_log_destination (void)
 Get current log destination. More...
 
int gslutil_interpret_log_level (const char *name, int *level)
 Interpret log level names. More...
 
void gslutil_log_level (int level)
 Change log level. More...
 
int gslutil_get_log_level (void)
 Query log level. More...
 

Detailed Description

This module contains a set of functions for convenient interaction with syslog. The LOG() macro is similar to syslog(), but it prepends line and function information. The LOG_RATE() macro can be used to perform rate-limited logging.

It is possible to change the destination of log messages using the gslutil_log_destination() messages.

The suggested uses for the various log levels are:

Macro Definition Documentation

◆ LOG

#define LOG (   level,
  fmt,
  ... 
)
Value:
do { \
if((level) <= _gslutil_min_log_level) { \
gslutil_log(level, "%s:%d: " fmt, __FUNCTION__, __LINE__ , ## __VA_ARGS__ ); \
} \
}while(0)

Log to syslog.

Parameters
levelThe log level (LOG_INFO, LOG_WARNING, LOG_ERR, etc.).
fmtFormat string.

This macro is a simple wrapper around syslog() that also prints the function and line number. fmt must be a string literal.

Note
level is evaluated more than once, so it should not be an expression with side effects. fmt must be a string literal.

◆ LOG_RATE

#define LOG_RATE (   rate,
  level,
  fmt,
  ... 
)
Value:
do { \
if(level <= _gslutil_min_log_level) { \
log_rate(rate, level, "%s:%d: " fmt, __FUNCTION__, __LINE__ , ## __VA_ARGS__ ); \
} \
}while(0)

Rate-limited logging.

Parameters
rateThe rate-limiting structure.
levelThe log level (LOG_INFO, LOG_WARNING, LOG_ERR, etc.).
fmtFormat string.

Like LOG(), only uses the rate structure to perform rate limiting. fmt must be a string literal.

◆ LOG_HEXDUMP

#define LOG_HEXDUMP (   data,
  len,
  desc,
  ... 
)
Value:
do { \
if(LOG_DEBUG <= _gslutil_min_log_level) { \
gslutil_log(LOG_DEBUG, "%s:%d: hexdump of %u bytes: " desc, \
__FUNCTION__, __LINE__, (unsigned)(len) , ## __VA_ARGS__ ); \
gslutil_log_hexdump((data), (len)); \
} \
}while(0)

Debug support: log hexdump.

Parameters
dataData to dump.
lenLength of data, in bytes.
descFormat string for description.

This function logs a hexdump of data to syslog. It is logged with level LOG_DEBUG, so by default calls to this macro will be ignored (but see gslutil_log_level()).

Note
len is evaluated more than once, so should not be an expression with side effects.

Enumeration Type Documentation

◆ gslutil_log_destination_t

Possible log destinations.

This list contains the possible destinations for the logfile.

Function Documentation

◆ gslutil_log_destination()

void gslutil_log_destination ( enum gslutil_log_destination_t  dest)

Change log destination.

Parameters
destLog destination.

This function changes the log destination.

◆ gslutil_get_log_destination()

enum gslutil_log_destination_t gslutil_get_log_destination ( void  )

Get current log destination.

Returns
Log destination as set by gslutil_log_destination().

◆ gslutil_interpret_log_level()

int gslutil_interpret_log_level ( const char *  name,
int *  level 
)

Interpret log level names.

Parameters
nameName to interpret.
[out]levelOn success, level is written to this argument.
Return values
0on success.
-1on error.

This function interprets the string name, matching it to "LOG_DEBUG" etc., and on success stores the associated log level value into level. If a match is found, level is set and 0 returned. If no match is found, level is unchanged and -1 is returned.

◆ gslutil_log_level()

void gslutil_log_level ( int  level)

Change log level.

Parameters
levelThe minimum required level for log messages.

This function allows the minimum required log level to be set. Any messages with a log level less severe than level are ignored. By default, the log level is set to LOG_INFO, meaning messages with a level of LOG_DEBUG are ignored. The test for the level is part of the LOG macros, so the format string and its arguments likely will not be evaluated at all if the minimum log level is not met.

◆ gslutil_get_log_level()

int gslutil_get_log_level ( void  )

Query log level.

Returns
Current log level, as set by gslutil_log_level().