SELKIELogger  1.0.0
Collaboration diagram for Logging support functions:

Classes

struct  program_state
 Program state and logging information. More...
 

Functions

void log_error (const program_state *s, const char *format,...)
 Output formatted error message. More...
 
void log_warning (const program_state *s, const char *format,...)
 Output formatted warning message. More...
 
void log_info (const program_state *s, const int level, const char *format,...)
 Output formatted information message at a given level. More...
 
FILE * openSerialNumberedFile (const char *prefix, const char *extension, char **name)
 Open dated, serial numbered file with given prefix and extension. More...
 
void destroy_program_state (program_state *s)
 Cleanly destroy program state. More...
 

Detailed Description

Function Documentation

◆ destroy_program_state()

void destroy_program_state ( program_state s)

Cleanly destroy program state.

Ensure dynamically allocated program_state members are freed.

Parameters
[in]sprogram_state to be destroyed

Definition at line 207 of file logging.c.

◆ log_error()

void log_error ( const program_state s,
const char *  format,
  ... 
)

Output formatted error message.

Outputs a provided error message, prepending the current program state and the marker "Error: ".

The error message and any additional arguments are passed to vfprintf in order to support formatted output.

Always outputs to stderr in addition to any configured log file.

Cannot be silenced by runtime configuration.

Parameters
[in]sprogram_state, used for state and configuration details
[in]formatprintf compatible format string

Definition at line 47 of file logging.c.

◆ log_info()

void log_info ( const program_state s,
const int  level,
const char *  format,
  ... 
)

Output formatted information message at a given level.

Outputs a provided message, prepending the current program state and the marker "Info:%d: ", with the level value substituted.

The error message and any additional arguments are passed to vfprintf in order to support formatted output.

The level is compared to the current verbosity to determine if messages are output to stdout, file, or both.

Parameters
[in]sprogram_state, used for state and configuration details
[in]levelDetail/Verbosity level for this message
[in]formatprintf compatible format string

Definition at line 125 of file logging.c.

◆ log_warning()

void log_warning ( const program_state s,
const char *  format,
  ... 
)

Output formatted warning message.

Outputs a provided warning message, prepending the current program state and the marker "Warning: ".

The error message and any additional arguments are passed to vfprintf in order to support formatted output.

Always outputs to stderr in addition to any configured log file.

Cannot be silenced by runtime configuration.

Parameters
[in]sprogram_state, used for state and configuration details
[in]formatprintf compatible format string

Definition at line 86 of file logging.c.

◆ openSerialNumberedFile()

FILE * openSerialNumberedFile ( const char *  prefix,
const char *  extension,
char **  name 
)

Open dated, serial numbered file with given prefix and extension.

Generates a file name with the form [prefix]YYYYMMDDXX.[extension], where XX is a two digit hexadecimal serial number. Starting from 0, the proposed file name is opened in exclusive create mode ("w+x"). If this fails because the file exists, the serial number is incremented and another attempt to create the file is made until either a) an unused serial number is found or b) the serial number reaches 0xFF.

If no valid file name can be generated, or if any other error is encountered, the function returns NULL.

Parameters
[in]prefixFile name prefix (can include a path)
[in]extensionFile extension
[out]nameFile name (without extension) used, if successful
Returns
Opened file handle, or null on failure

Definition at line 169 of file logging.c.