The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Support functions for logging in FreeRADIUS libraries. More...
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/log.h>
#include <freeradius-devel/util/print.h>
#include <freeradius-devel/util/sbuff.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/atexit.h>
#include <freeradius-devel/util/value.h>
#include <freeradius-devel/util/time.h>
#include <fcntl.h>
Go to the source code of this file.
Functions | |
static int | _fr_log_pool_free (void *arg) |
Cleanup the memory pool used by vlog_request. More... | |
static int | _restore_std_legacy (UNUSED int sig) |
On fault, reset STDOUT and STDERR to something useful. More... | |
static ssize_t | _syslog_write (UNUSED void *cookie, const char *buf, size_t size) |
Write complete lines to syslog. More... | |
void | fr_canonicalize_error (TALLOC_CTX *ctx, char **sp, char **text, ssize_t slen, char const *fmt) |
Canonicalize error strings, removing tabs, and generate spaces for error marker. More... | |
void | fr_log (fr_log_t const *log, fr_log_type_t type, char const *file, int line, char const *fmt,...) |
Send a server log message to its destination. More... | |
int | fr_log_close (fr_log_t *log) |
Universal close function for all logging destinations. More... | |
void | fr_log_fd_event (UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *uctx) |
Function to provide as the readable callback to the event loop. More... | |
void | fr_log_global_free (void) |
Restores the original stdout and stderr FDs, closes the pipes and removes them from the event loop. More... | |
int | fr_log_global_init (fr_event_list_t *el, bool daemonize) |
Manipulate stderr and stdout so that was capture all data send to it from libraries. More... | |
void | fr_log_hex (fr_log_t const *log, fr_log_type_t type, char const *file, int line, uint8_t const *data, size_t data_len, char const *line_prefix_fmt,...) |
Print out hex block. More... | |
void | fr_log_hex_marker (fr_log_t const *log, fr_log_type_t type, char const *file, int line, uint8_t const *data, size_t data_len, ssize_t marker_idx, char const *marker, char const *line_prefix_fmt,...) |
Print out hex block. More... | |
int | fr_log_init_file (fr_log_t *log, char const *file) |
Initialise a file logging destination. More... | |
int | fr_log_init_fp (fr_log_t *log, FILE *fp) |
Initialise a file logging destination to a FILE*. More... | |
int | fr_log_init_func (fr_log_t *log, cookie_write_function_t write, cookie_close_function_t close, void *uctx) |
Initialise a function based logging destination. More... | |
int | fr_log_init_legacy (fr_log_t *log, bool daemonize) |
Initialise file descriptors based on logging destination. More... | |
int | fr_log_init_std (fr_log_t *log, fr_log_dst_t dst_type) |
Initialise log dst for stdout, stderr or /dev/null. More... | |
int | fr_log_init_syslog (fr_log_t *log) |
Initialise a syslog logging destination. More... | |
void | fr_log_marker (fr_log_t const *log, fr_log_type_t type, char const *file, int line, char const *str, size_t str_len, ssize_t marker_idx, char const *marker, char const *line_prefix_fmt,...) |
Print out an error marker. More... | |
void | fr_log_perror (fr_log_t const *log, fr_log_type_t type, char const *file, int line, fr_log_perror_format_t const *rules, char const *fmt,...) |
Drain any outstanding messages from the fr_strerror buffers. More... | |
TALLOC_CTX * | fr_log_pool_init (void) |
talloc ctx to use when composing log messages More... | |
void | fr_vlog (fr_log_t const *log, fr_log_type_t type, char const *file, int line, char const *fmt, va_list ap) |
Send a server log message to its destination. More... | |
void | fr_vlog_perror (fr_log_t const *log, fr_log_type_t type, char const *file, int line, fr_log_perror_format_t const *f_rules, char const *fmt, va_list ap) |
Drain any outstanding messages from the fr_strerror buffers. More... | |
Variables | |
static fr_table_num_ordered_t const | colours [] |
Maps log categories to VT100 style/colour escape sequences. More... | |
static size_t | colours_len = NUM_ELEMENTS(colours) |
fr_log_t | default_log |
static FILE * | devnull |
File handle for /dev/null. More... | |
int | fr_debug_lvl = 0 |
FILE * | fr_log_fp = NULL |
fr_table_num_ordered_t const | fr_log_levels [] |
Maps log categories to message prefixes. More... | |
size_t | fr_log_levels_len = NUM_ELEMENTS(fr_log_levels) |
static _Thread_local TALLOC_CTX * | fr_log_pool |
bool | fr_log_rate_limit = true |
Whether repeated log entries should be rate limited. More... | |
static uint32_t | location_indent = 30 |
bool | log_dates_utc = false |
static fr_event_list_t * | log_el |
Event loop we use for process logging data. More... | |
static _Thread_local fr_log_type_t | log_msg_type |
The type of the last message logged. More... | |
static fr_log_fd_event_ctx_t | stderr_ctx |
Logging ctx for stderr. More... | |
static int | stderr_fd = -1 |
The original unmolested stderr file descriptor. More... | |
static int | stderr_pipe [2] |
Pipe we use to transport stderr data. More... | |
static fr_log_fd_event_ctx_t | stdout_ctx |
Logging ctx for stdout. More... | |
static int | stdout_fd = -1 |
The original unmolested stdout file descriptor. More... | |
static int | stdout_pipe [2] |
Pipe we use to transport stdout data. More... | |
VT100 escape sequences | |
These sequences may be written to VT100 terminals to change the colour and style of the text. | |
#define | VTC_BOLD "\x1b[1m" |
Embolden following text. More... | |
#define | VTC_RED "\x1b[31m" |
Colour following text red. More... | |
#define | VTC_RESET "\x1b[0m" |
Reset terminal text to default style/colour. More... | |
#define | VTC_YELLOW "\x1b[33m" |
Colour following text yellow. More... | |
Support functions for logging in FreeRADIUS libraries.
Definition in file log.c.
#define VTC_RESET "\x1b[0m" |
|
static |
|
static |
void fr_canonicalize_error | ( | TALLOC_CTX * | ctx, |
char ** | sp, | ||
char ** | text, | ||
ssize_t | slen, | ||
char const * | fmt | ||
) |
Canonicalize error strings, removing tabs, and generate spaces for error marker.
Used to produce error messages such as this:
I'm a string with a parser # error ^ Unexpected character in string
With code resembling this:
sp | Where to write a dynamically allocated buffer of spaces used to indent the error text. |
text | Where to write the canonicalized version of fmt (the error text). |
ctx | to allocate the spaces and text buffers in. |
slen | of error marker. Expects negative integer value, as returned by parse functions. |
fmt | to canonicalize. |
Definition at line 90 of file log.c.
void fr_log | ( | fr_log_t const * | log, |
fr_log_type_t | type, | ||
char const * | file, | ||
int | line, | ||
char const * | fmt, | ||
... | |||
) |
Send a server log message to its destination.
log | destination. |
type | of log message. |
file | where the log message originated |
line | where the log message originated |
fmt | with printf style substitution tokens. |
... | Substitution arguments. |
Definition at line 583 of file log.c.
int fr_log_close | ( | fr_log_t * | log | ) |
void fr_log_fd_event | ( | UNUSED fr_event_list_t * | el, |
int | fd, | ||
UNUSED int | flags, | ||
void * | uctx | ||
) |
Function to provide as the readable callback to the event loop.
Writes any data read from a file descriptor to the request log, tries very hard not to chop lines in the middle, but will split at 1024 byte boundaries if forced to.
[in] | el | UNUSED |
[in] | fd | UNUSED |
[in] | flags | UNUSED |
[in] | uctx | Pointer to a log_fd_event_ctx_t |
Definition at line 179 of file log.c.
void fr_log_global_free | ( | void | ) |
int fr_log_global_init | ( | fr_event_list_t * | el, |
bool | daemonize | ||
) |
Manipulate stderr and stdout so that was capture all data send to it from libraries.
[in] | el | The event list we use to process logging data. |
[in] | daemonize | Whether the server is starting as a daemon. |
Definition at line 1225 of file log.c.
void fr_log_hex | ( | fr_log_t const * | log, |
fr_log_type_t | type, | ||
char const * | file, | ||
int | line, | ||
uint8_t const * | data, | ||
size_t | data_len, | ||
char const * | line_prefix_fmt, | ||
... | |||
) |
Print out hex block.
[in] | log | destination. |
[in] | type | of log message. |
[in] | file | src file the log message was generated in. |
[in] | line | number the log message was generated on. |
[in] | data | to print. |
[in] | data_len | length of data. |
[in] | line_prefix_fmt | Prefix to add to the marker messages. |
[in] | ... | Arguments for line_prefix_fmt. |
Definition at line 784 of file log.c.
void fr_log_hex_marker | ( | fr_log_t const * | log, |
fr_log_type_t | type, | ||
char const * | file, | ||
int | line, | ||
uint8_t const * | data, | ||
size_t | data_len, | ||
ssize_t | marker_idx, | ||
char const * | marker, | ||
char const * | line_prefix_fmt, | ||
... | |||
) |
Print out hex block.
[in] | log | destination. |
[in] | type | of log message. |
[in] | file | src file the log message was generated in. |
[in] | line | number the log message was generated on. |
[in] | data | to print. |
[in] | data_len | length of data. |
[in] | marker_idx | Where to place the marker. May be negative. |
[in] | marker | text to print at marker_idx. |
[in] | line_prefix_fmt | Prefix to add to the marker messages. |
[in] | ... | Arguments for line_prefix_fmt. |
Definition at line 831 of file log.c.
int fr_log_init_file | ( | fr_log_t * | log, |
char const * | file | ||
) |
int fr_log_init_fp | ( | fr_log_t * | log, |
FILE * | fp | ||
) |
int fr_log_init_func | ( | fr_log_t * | log, |
cookie_write_function_t | write, | ||
cookie_close_function_t | close, | ||
void * | uctx | ||
) |
Initialise a function based logging destination.
[out] | log | Destination to initialise. |
[in] | write | Called when a complete log line is ready for writing. |
[in] | close | May be NULL. Called when the logging destination has been closed. |
[in] | uctx | for the write and close functions. |
Definition at line 1165 of file log.c.
Initialise file descriptors based on logging destination.
log | Logger to manipulate. |
daemonize | Whether the server is starting as a daemon. |
Definition at line 907 of file log.c.
int fr_log_init_std | ( | fr_log_t * | log, |
fr_log_dst_t | dst_type | ||
) |
int fr_log_init_syslog | ( | fr_log_t * | log | ) |
void fr_log_marker | ( | fr_log_t const * | log, |
fr_log_type_t | type, | ||
char const * | file, | ||
int | line, | ||
char const * | str, | ||
size_t | str_len, | ||
ssize_t | marker_idx, | ||
char const * | marker, | ||
char const * | line_prefix_fmt, | ||
... | |||
) |
Print out an error marker.
[in] | log | destination. |
[in] | type | of log message. |
[in] | file | src file the log message was generated in. |
[in] | line | number the log message was generated on. |
[in] | str | Subject string we're printing a marker for. |
[in] | str_len | Subject string length. Use SIZE_MAX for the length of the string. |
[in] | marker_idx | Where to place the marker. May be negative. |
[in] | marker | text to print at marker_idx. |
[in] | line_prefix_fmt | Prefix to add to the marker messages. |
[in] | ... | Arguments for line_prefix_fmt. |
Definition at line 734 of file log.c.
void fr_log_perror | ( | fr_log_t const * | log, |
fr_log_type_t | type, | ||
char const * | file, | ||
int | line, | ||
fr_log_perror_format_t const * | rules, | ||
char const * | fmt, | ||
... | |||
) |
Drain any outstanding messages from the fr_strerror buffers.
This function drains any messages from fr_strerror buffer adding a prefix (fmt) to the first message.
[in] | log | destination. |
[in] | type | of log message. |
[in] | file | src file the log message was generated in. |
[in] | line | number the log message was generated on. |
[in] | rules | for printing multiline errors. |
[in] | fmt | with printf style substitution tokens. |
[in] | ... | Substitution arguments. |
Definition at line 709 of file log.c.
TALLOC_CTX* fr_log_pool_init | ( | void | ) |
talloc ctx to use when composing log messages
Functions must ensure that they allocate a new ctx from the one returned here, and that this ctx is freed before the function returns.
Definition at line 316 of file log.c.
void fr_vlog | ( | fr_log_t const * | log, |
fr_log_type_t | type, | ||
char const * | file, | ||
int | line, | ||
char const * | fmt, | ||
va_list | ap | ||
) |
Send a server log message to its destination.
[in] | log | destination. |
[in] | type | of log message. |
[in] | file | src file the log message was generated in. |
[in] | line | number the log message was generated on. |
[in] | fmt | with printf style substitution tokens. |
[in] | ap | Substitution arguments. |
Definition at line 344 of file log.c.
void fr_vlog_perror | ( | fr_log_t const * | log, |
fr_log_type_t | type, | ||
char const * | file, | ||
int | line, | ||
fr_log_perror_format_t const * | f_rules, | ||
char const * | fmt, | ||
va_list | ap | ||
) |
Drain any outstanding messages from the fr_strerror buffers.
This function drains any messages from fr_strerror buffer prefixing the first message with fmt + args.
If a prefix is specified in rules, this is prepended to all lines logged. The prefix is useful for adding context, i.e. configuration file and line number information.
[in] | log | destination. |
[in] | type | of log message. |
[in] | file | src file the log message was generated in. |
[in] | line | number the log message was generated on. |
[in] | f_rules | for printing multiline errors. |
[in] | fmt | with printf style substitution tokens. |
[in] | ap | Substitution arguments. |
Definition at line 614 of file log.c.
|
static |
|
static |
fr_log_t default_log |
fr_table_num_ordered_t const fr_log_levels[] |
Maps log categories to message prefixes.
size_t fr_log_levels_len = NUM_ELEMENTS(fr_log_levels) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |