![]() |
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/syserror.h>#include <freeradius-devel/util/value.h>#include <fcntl.h>
Include dependency graph for log.c: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. | |
| static int | _restore_std_legacy (UNUSED int sig) |
| On fault, reset STDOUT and STDERR to something useful. | |
| static ssize_t | _syslog_write (UNUSED void *cookie, const char *buf, size_t size) |
| Write complete lines to syslog. | |
| 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. | |
| 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. | |
| int | fr_log_close (fr_log_t *log) |
| Universal close function for all logging destinations. | |
| 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. | |
| void | fr_log_global_free (void) |
| Restores the original stdout and stderr FDs, closes the pipes and removes them from the event loop. | |
| 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. | |
| 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. | |
| 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. | |
| int | fr_log_init_file (fr_log_t *log, char const *file) |
| Initialise a file logging destination. | |
| int | fr_log_init_fp (fr_log_t *log, FILE *fp) |
| Initialise a file logging destination to a FILE*. | |
| 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. | |
| int | fr_log_init_legacy (fr_log_t *log, bool daemonize) |
| Initialise file descriptors based on logging destination. | |
| int | fr_log_init_std (fr_log_t *log, fr_log_dst_t dst_type) |
| Initialise log dst for stdout, stderr or /dev/null. | |
| int | fr_log_init_syslog (fr_log_t *log) |
| Initialise a syslog logging destination. | |
| 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. | |
| 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. | |
| TALLOC_CTX * | fr_log_pool_init (void) |
| talloc ctx to use when composing log messages | |
| 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. | |
| 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. | |
Variables | |
| static fr_table_num_ordered_t const | colours [] |
| Maps log categories to VT100 style/colour escape sequences. | |
| static size_t | colours_len = NUM_ELEMENTS(colours) |
| fr_log_t | default_log |
| static FILE * | devnull |
| File handle for /dev/null. | |
| 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. | |
| 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. | |
| 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. | |
| static _Thread_local fr_log_type_t | log_msg_type |
| The type of the last message logged. | |
| static fr_log_fd_event_ctx_t | stderr_ctx |
| Logging ctx for stderr. | |
| static int | stderr_fd = -1 |
| The original unmolested stderr file descriptor. | |
| static int | stderr_pipe [2] |
| Pipe we use to transport stderr data. | |
| static fr_log_fd_event_ctx_t | stdout_ctx |
| Logging ctx for stdout. | |
| static int | stdout_fd = -1 |
| The original unmolested stdout file descriptor. | |
| static int | stdout_pipe [2] |
| Pipe we use to transport stdout data. | |
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. | |
| #define | VTC_RED "\x1b[31m" |
| Colour following text red. | |
| #define | VTC_RESET "\x1b[0m" |
| Reset terminal text to default style/colour. | |
| #define | VTC_YELLOW "\x1b[33m" |
| Colour following text yellow. | |
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 87 of file log.c.
Here is the caller graph for this function:| 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 577 of file log.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 176 of file log.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 1219 of file log.c.
Here is the call graph for this function:| 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 778 of file log.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 825 of file log.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 1159 of file log.c.
Here is the call graph for this function:Initialise file descriptors based on logging destination.
| log | Logger to manipulate. |
| daemonize | Whether the server is starting as a daemon. |
Definition at line 901 of file log.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 728 of file log.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 703 of file log.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 313 of file log.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 341 of file log.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 608 of file log.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
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) |
| bool fr_log_rate_limit = true |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
1.9.8