All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions | Variables
log.c File Reference

Logging functions used by the server core. More...

#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/rad_assert.h>
#include <fcntl.h>
#include <sys/file.h>
+ Include dependency graph for log.c:

Go to the source code of this file.

Macros

VT100 escape sequences

These sequences may be written to VT100 terminals to change the colour and style of the text.

fprintf(stdout, VTC_RED "This text will be coloured red" VTC_RESET);
#define VTC_RED   "\x1b[31m"
 Colour following text red. More...
 
#define VTC_YELLOW   "\x1b[33m"
 Colour following text yellow. More...
 
#define VTC_BOLD   "\x1b[1m"
 Embolden following text. More...
 
#define VTC_RESET   "\x1b[0m"
 Reset terminal text to default style/colour. More...
 

Functions

static int _restore_std (UNUSED int sig)
 On fault, reset STDOUT and STDERR to something useful. More...
 
bool debug_enabled (log_type_t type, log_lvl_t lvl)
 Whether a server debug message should be logged. More...
 
int radlog (log_type_t type, char const *msg,...)
 Send a server log message to its destination. More...
 
static int radlog_always (log_type_t type, char const *msg,...) CC_HINT(format(printf
 Send a server log message to its destination without evaluating its debug level. More...
 
bool radlog_debug_enabled (log_type_t type, log_lvl_t lvl, REQUEST *request)
 Whether a request specific debug message should be logged. More...
 
int radlog_init (fr_log_t *log, bool daemonize)
 Initialise file descriptors based on logging destination. More...
 
void radlog_request (log_type_t type, log_lvl_t lvl, REQUEST *request, char const *msg,...)
 Martial variadic log arguments into a va_list and pass to normal logging functions. More...
 
void radlog_request_error (log_type_t type, log_lvl_t lvl, REQUEST *request, char const *msg,...)
 Martial variadic log arguments into a va_list and pass to error logging functions. More...
 
void radlog_request_marker (log_type_t type, log_lvl_t lvl, REQUEST *request, char const *msg, size_t idx, char const *error)
 Write the string being parsed, and a marker showing where the parse error occurred. More...
 
bool rate_limit_enabled (void)
 Whether rate limiting is enabled. More...
 
int vradlog (log_type_t type, char const *msg, va_list ap)
 Send a server log message to its destination. More...
 
void vradlog_request (log_type_t type, log_lvl_t lvl, REQUEST *request, char const *msg, va_list ap)
 Send a log message to its destination, possibly including fields from the request. More...
 

Variables

static const FR_NAME_NUMBER colours []
 Maps log categories to VT100 style/colour escape sequences. More...
 
fr_log_t default_log
 
static const FR_NAME_NUMBER levels []
 Maps log categories to message prefixes. More...
 
bool log_dates_utc = false
 
const FR_NAME_NUMBER log_str2dst []
 
log_lvl_t rad_debug_lvl = 0
 Global debugging level. More...
 
static bool rate_limit = true
 Whether repeated log entries should be rate limited. More...
 
static char const spaces [] = " "
 
static int stderr_fd = -1
 The original unmolested stderr file descriptor. More...
 
static int stdout_fd = -1
 The original unmolested stdout file descriptor. More...
 
const FR_NAME_NUMBER syslog_facility_table []
 Syslog facility table. More...
 
const FR_NAME_NUMBER syslog_severity_table []
 Syslog severity table. More...
 

Detailed Description

Logging functions used by the server core.

Id:
a4a1d89fff3d499509b384c7986132f06759dc0b

Definition in file log.c.

Macro Definition Documentation

#define VTC_BOLD   "\x1b[1m"

Embolden following text.

Definition at line 81 of file log.c.

#define VTC_RED   "\x1b[31m"

Colour following text red.

Definition at line 79 of file log.c.

#define VTC_RESET   "\x1b[0m"

Reset terminal text to default style/colour.

Definition at line 82 of file log.c.

#define VTC_YELLOW   "\x1b[33m"

Colour following text yellow.

Definition at line 80 of file log.c.

Function Documentation

static int _restore_std ( UNUSED int  sig)
static

On fault, reset STDOUT and STDERR to something useful.

Returns
0

Definition at line 232 of file log.c.

+ Here is the caller graph for this function:

bool debug_enabled ( log_type_t  type,
log_lvl_t  lvl 
)
inline

Whether a server debug message should be logged.

Parameters
typeof message.
lvlof debugging this message should be logged at.
Returns
  • true if message should be logged.
  • false if message shouldn't be logged.

Definition at line 579 of file log.c.

int radlog ( log_type_t  type,
char const *  msg,
  ... 
)

Send a server log message to its destination.

Parameters
typeof log message.
msgwith printf style substitution tokens.
...Substitution arguments.

Definition at line 534 of file log.c.

+ Here is the call graph for this function:

static int static int radlog_always ( log_type_t  type,
char const *  msg,
  ... 
)
static

Send a server log message to its destination without evaluating its debug level.

Parameters
typeof log message.
msgwith printf style substitution tokens.
...Substitution arguments.

Definition at line 559 of file log.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool radlog_debug_enabled ( log_type_t  type,
log_lvl_t  lvl,
REQUEST request 
)
inline

Whether a request specific debug message should be logged.

Parameters
typeof message.
lvlof debugging this message should be logged at.
requestThe current request.
Returns
  • true if message should be logged.
  • false if message shouldn't be logged.

Definition at line 604 of file log.c.

+ Here is the caller graph for this function:

int radlog_init ( fr_log_t log,
bool  daemonize 
)

Initialise file descriptors based on logging destination.

Parameters
logLogger to manipulate.
daemonizeWhether the server is starting as a daemon.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 257 of file log.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void radlog_request ( log_type_t  type,
log_lvl_t  lvl,
REQUEST request,
char const *  msg,
  ... 
)

Martial variadic log arguments into a va_list and pass to normal logging functions.

See Also
radlog_request_error for more details.
Parameters
typethe log category.
lvlof debugging this message should be logged at.
requestThe current request.
msgwith printf style substitution tokens.
...Substitution arguments.

Definition at line 821 of file log.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void radlog_request_error ( log_type_t  type,
log_lvl_t  lvl,
REQUEST request,
char const *  msg,
  ... 
)

Martial variadic log arguments into a va_list and pass to error logging functions.

This could all be done in a macro, but it turns out some implementations of the variadic macros do not work at all well if the va_list being written to is further up the stack (which is required as you still need a function to convert the elipses into a va_list).

So, we use this small wrapper function instead, which will hopefully guarantee consistent behaviour.

Parameters
typethe log category.
lvlof debugging this message should be logged at.
requestThe current request.
msgwith printf style substitution tokens.
...Substitution arguments.

Definition at line 851 of file log.c.

+ Here is the call graph for this function:

void radlog_request_marker ( log_type_t  type,
log_lvl_t  lvl,
REQUEST request,
char const *  msg,
size_t  idx,
char const *  error 
)

Write the string being parsed, and a marker showing where the parse error occurred.

Parameters
typethe log category.
lvlof debugging this message should be logged at.
requestThe current request.
msgstring we were parsing.
idxThe position of the marker relative to the string.
errorWhat the parse error was.

Definition at line 873 of file log.c.

+ Here is the call graph for this function:

bool rate_limit_enabled ( void  )

Whether rate limiting is enabled.

Definition at line 588 of file log.c.

int vradlog ( log_type_t  type,
char const *  msg,
va_list  ap 
)

Send a server log message to its destination.

Parameters
typeof log message.
msgwith printf style substitution tokens.
apSubstitution arguments.

Definition at line 373 of file log.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void vradlog_request ( log_type_t  type,
log_lvl_t  lvl,
REQUEST request,
char const *  msg,
va_list  ap 
)

Send a log message to its destination, possibly including fields from the request.

Parameters
typeof log message, L_ERR, L_WARN, L_INFO, L_DBG.
lvlMinimum required server or request level to output this message.
requestThe current request.
msgwith printf style substitution tokens.
apSubstitution arguments.

Definition at line 633 of file log.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const FR_NAME_NUMBER colours[]
static
Initial value:
= {
{ "", L_DBG },
{ VTC_RED, L_ERR },
{ NULL, 0 }
}
Only displayed when debugging is enabled.
Definition: log.h:41
Less severe warning only displayed when debugging is enabled.
Definition: log.h:44
Warning.
Definition: log.h:37
Less severe error only displayed when debugging is enabled.
Definition: log.h:45
Error message.
Definition: log.h:36
#define VTC_BOLD
Embolden following text.
Definition: log.c:81
#define VTC_RED
Colour following text red.
Definition: log.c:79
Accounting messages.
Definition: log.h:39
Authentication message.
Definition: log.h:34
#define VTC_YELLOW
Colour following text yellow.
Definition: log.c:80
Proxy messages.
Definition: log.h:38
Error only displayed when debugging is enabled.
Definition: log.h:43
Warning only displayed when debugging is enabled.
Definition: log.h:42
Informational message.
Definition: log.h:35

Maps log categories to VT100 style/colour escape sequences.

Definition at line 87 of file log.c.

fr_log_t default_log
Initial value:
= {
.colourise = false,
.fd = STDOUT_FILENO,
.dst = L_DST_STDOUT,
.file = NULL,
}
Log to stdout.
Definition: log.h:58

Definition at line 216 of file log.c.

const FR_NAME_NUMBER levels[]
static
Initial value:
= {
{ ": Debug: ", L_DBG },
{ ": Auth: ", L_AUTH },
{ ": Proxy: ", L_PROXY },
{ ": Info: ", L_INFO },
{ ": Warning: ", L_WARN },
{ ": Acct: ", L_ACCT },
{ ": Error: ", L_ERR },
{ ": WARNING: ", L_DBG_WARN },
{ ": ERROR: ", L_DBG_ERR },
{ ": WARNING: ", L_DBG_WARN_REQ },
{ ": ERROR: ", L_DBG_ERR_REQ },
{ NULL, 0 }
}
Only displayed when debugging is enabled.
Definition: log.h:41
Less severe warning only displayed when debugging is enabled.
Definition: log.h:44
Warning.
Definition: log.h:37
Less severe error only displayed when debugging is enabled.
Definition: log.h:45
Error message.
Definition: log.h:36
Accounting messages.
Definition: log.h:39
Authentication message.
Definition: log.h:34
Proxy messages.
Definition: log.h:38
Error only displayed when debugging is enabled.
Definition: log.h:43
Warning only displayed when debugging is enabled.
Definition: log.h:42
Informational message.
Definition: log.h:35

Maps log categories to message prefixes.

Definition at line 54 of file log.c.

bool log_dates_utc = false

Definition at line 214 of file log.c.

const FR_NAME_NUMBER log_str2dst[]
Initial value:
= {
{ "null", L_DST_NULL },
{ "files", L_DST_FILES },
{ "syslog", L_DST_SYSLOG },
{ "stdout", L_DST_STDOUT },
{ "stderr", L_DST_STDERR },
{ NULL, L_DST_NUM_DEST }
}
Log to syslog.
Definition: log.h:60
Log to stderr.
Definition: log.h:61
Log to a file on disk.
Definition: log.h:59
Discard log messages.
Definition: log.h:63
Log to stdout.
Definition: log.h:58

Definition at line 205 of file log.c.

log_lvl_t rad_debug_lvl = 0

Global debugging level.

Definition at line 49 of file log.c.

bool rate_limit = true
static

Whether repeated log entries should be rate limited.

Definition at line 50 of file log.c.

char const spaces[] = " "
static

Definition at line 226 of file log.c.

int stderr_fd = -1
static

The original unmolested stderr file descriptor.

Definition at line 223 of file log.c.

int stdout_fd = -1
static

The original unmolested stdout file descriptor.

Definition at line 224 of file log.c.

const FR_NAME_NUMBER syslog_facility_table[]

Syslog facility table.

Maps syslog facility keywords, to the syslog facility macros defined in the system's syslog.h.

Note
Not all facilities are supported by every operating system. If a facility is unavailable it will not appear in the table.

Definition at line 110 of file log.c.

const FR_NAME_NUMBER syslog_severity_table[]
Initial value:
= {
{ NULL, -1 }
}

Syslog severity table.

Maps syslog severity keywords, to the syslog severity macros defined in the system's syslog.h file.

Definition at line 177 of file log.c.