libgslutil
1.2.3
|
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... | |
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:
LOG_DEBUG
- debugging, ignored by default (but see gslutil_log_level()). LOG_INFO
- verbose informational messages, including user-requested debug dumps. LOG_NOTICE
- important but expected events (daemon startup/shutdown notifications, start of maintenance, etc.). LOG_WARNING
- a condition that the user might want to do something about, but not an actual system call error (e.g. low on disk space, name too long and was truncated, etc.). LOG_ERR
- system call error that doesn't cause an immediate exit(). LOG_CRIT
- daemon quitting due to error condition. LOG_ALERT
- the user really needs to do something about this. Preferably we also generate a system event. LOG_EMERG
- we're probably going to have to reboot now. Generally only used in the watchdog code. Should generate a system event. #define LOG | ( | level, | |
fmt, | |||
... | |||
) |
Log to syslog.
level | The log level (LOG_INFO , LOG_WARNING , LOG_ERR , etc.). |
fmt | Format string. |
This macro is a simple wrapper around syslog() that also prints the function and line number. fmt must be a string literal.
#define LOG_RATE | ( | rate, | |
level, | |||
fmt, | |||
... | |||
) |
Rate-limited logging.
rate | The rate-limiting structure. |
level | The log level (LOG_INFO , LOG_WARNING , LOG_ERR , etc.). |
fmt | Format string. |
Like LOG(), only uses the rate structure to perform rate limiting. fmt must be a string literal.
#define LOG_HEXDUMP | ( | data, | |
len, | |||
desc, | |||
... | |||
) |
Debug support: log hexdump.
data | Data to dump. |
len | Length of data, in bytes. |
desc | Format 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()).
Possible log destinations.
This list contains the possible destinations for the logfile.
void gslutil_log_destination | ( | enum gslutil_log_destination_t | dest | ) |
Change log destination.
dest | Log destination. |
This function changes the log destination.
enum gslutil_log_destination_t gslutil_get_log_destination | ( | void | ) |
Get current log destination.
int gslutil_interpret_log_level | ( | const char * | name, |
int * | level | ||
) |
Interpret log level names.
name | Name to interpret. | |
[out] | level | On success, level is written to this argument. |
0 | on success. |
-1 | on 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.
void gslutil_log_level | ( | int | level | ) |
Change log level.
level | The 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.
int gslutil_get_log_level | ( | void | ) |
Query log level.