Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
LOGGING: logging to console, to file, to syslog, to event log

Data Structures

struct  TS_LOG
 ThreadSafe LOGging structure. More...
 

Macros

#define LOG_ALERT   1
 action must be taken immediately
 
#define LOG_CRIT   2
 critical conditions
 
#define LOG_DEBUG   7
 debug-level messages
 
#define LOG_EMERG   0
 system is unusable
 
#define LOG_ERR   3
 error conditions
 
#define LOG_FILE   -3
 internal, logging to file
 
#define LOG_INFO   6
 informational
 
#define LOG_NOTICE   5
 normal but significant condition
 
#define LOG_NULL   -1
 no log output
 
#define LOG_STDERR   -4
 internal, default LOG_TYPE
 
#define LOG_SYSJRNL   100
 to sysjrnl
 
#define LOG_WARNING   4
 warning conditions
 
#define n_log(__LEVEL__, ...)
 Logging function wrapper to get line and func.
 

Functions

void _n_log (int level, const char *file, const char *func, int line, const char *format,...)
 Full log function.
 
int close_safe_logging (TS_LOG *log)
 close a thread-safe logging file
 
void close_sysjrnl (void)
 close syslog / free name for event log
 
FILE * get_log_file (void)
 get the log file name if any
 
int get_log_level (void)
 Return the global log level.
 
int open_safe_logging (TS_LOG **log, char *pathname, char *opt)
 Open a thread-safe logging file.
 
char * open_sysjrnl (const char *identity)
 Open a syslog / set name for event log.
 
int set_log_file (char *file)
 set a file as standard log output
 
void set_log_level (const int log_level)
 Set global log level.
 
int write_safe_log (TS_LOG *log, char *pat,...)
 write to a thread-safe logging file
 

Detailed Description


Data Structure Documentation

◆ TS_LOG

struct TS_LOG

ThreadSafe LOGging structure.

Examples
ex_log.c.

Definition at line 94 of file n_log.h.

+ Collaboration diagram for TS_LOG:
Data Fields
FILE * file File handler.
pthread_mutex_t LOG_MUTEX mutex for thread-safe writting

Macro Definition Documentation

◆ LOG_ALERT

#define LOG_ALERT   1

action must be taken immediately

Examples
ex_log.c.

Definition at line 71 of file n_log.h.

◆ LOG_CRIT

#define LOG_CRIT   2

critical conditions

Examples
ex_log.c.

Definition at line 73 of file n_log.h.

◆ LOG_DEBUG

◆ LOG_EMERG

#define LOG_EMERG   0

system is unusable

Examples
ex_log.c.

Definition at line 69 of file n_log.h.

◆ LOG_ERR

◆ LOG_FILE

#define LOG_FILE   -3

internal, logging to file

Definition at line 47 of file n_log.h.

◆ LOG_INFO

◆ LOG_NOTICE

◆ LOG_NULL

◆ LOG_STDERR

#define LOG_STDERR   -4

internal, default LOG_TYPE

Examples
ex_exceptions.c, ex_pcre.c, and ex_signals.c.

Definition at line 49 of file n_log.h.

◆ LOG_SYSJRNL

#define LOG_SYSJRNL   100

to sysjrnl

Definition at line 51 of file n_log.h.

◆ LOG_WARNING

#define LOG_WARNING   4

warning conditions

Examples
ex_log.c.

Definition at line 77 of file n_log.h.

◆ n_log

Function Documentation

◆ _n_log()

void _n_log ( int  level,
const char *  file,
const char *  func,
int  line,
const char *  format,
  ... 
)

Full log function.

Must be wrapped in a MACRO to get the correct file/func/line information

Full log function.

log( level , const char *format , ... ) is a macro around _log

Parameters
levelLogging level
fileFile containing the emitted log
funcFunction emitting the log
lineLine of the log
formatFormat and string of the log, printf style

Definition at line 267 of file n_log.c.

References _str, COLOR_BLUE, COLOR_CYAN, COLOR_GREEN, COLOR_MAGENTA, COLOR_RED, COLOR_RESET, COLOR_WHITE, COLOR_YELLOW, FreeNoLog, get_log_level(), LOG_ALERT, LOG_CRIT, LOG_DEBUG, LOG_EMERG, LOG_ERR, log_file, LOG_INFO, log_level, LOG_NOTICE, LOG_NULL, LOG_SYSJRNL, LOG_TYPE, LOG_WARNING, Malloc, prioritynames, proc_name, terminal_support_colors, and vasprintf().

Referenced by _n_nodup_log(), _n_nodup_log_indexed(), and _npcre_print_error().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ close_safe_logging()

int close_safe_logging ( TS_LOG log)

close a thread-safe logging file

Parameters
logA TS_LOG handler
Returns
TRUE on success, FALSE on error

Definition at line 479 of file n_log.c.

References TS_LOG::file, Free, and TS_LOG::LOG_MUTEX.

Referenced by main().

+ Here is the caller graph for this function:

◆ close_sysjrnl()

void close_sysjrnl ( void  )

close syslog / free name for event log

close syslog / free name for event log

Definition at line 109 of file n_log.c.

References FreeNoLog, and proc_name.

Referenced by main().

+ Here is the caller graph for this function:

◆ get_log_file()

FILE * get_log_file ( void  )

get the log file name if any

get the log file name if any

Returns
a valid FILE handle or NULL

Definition at line 197 of file n_log.c.

References log_file.

Referenced by main(), and main().

+ Here is the caller graph for this function:

◆ get_log_level()

int get_log_level ( void  )

Return the global log level.

Possible values: NOLOG , NOTICE , VERBOSE , ERROR , DEBUG

Return the global log level.

Returns
static int LOG_LEVEL

Definition at line 158 of file n_log.c.

References LOG_LEVEL.

Referenced by _n_log(), and main().

+ Here is the caller graph for this function:

◆ open_safe_logging()

int open_safe_logging ( TS_LOG **  log,
char *  pathname,
char *  opt 
)

Open a thread-safe logging file.

Parameters
logA TS_LOG handler
pathnameThe file path (if any) and name
optOptions for opening (please never forget to use "w")
Returns
TRUE on success , FALSE on error , -1000 if already open

Definition at line 382 of file n_log.c.

References _str, TS_LOG::file, Free, LOG_ERR, Malloc, and n_log.

Referenced by main().

+ Here is the caller graph for this function:

◆ open_sysjrnl()

char * open_sysjrnl ( const char *  identity)

Open a syslog / set name for event log.

Open a syslog / set name for event log.

Parameters
identityTag for syslog or NULL to use argv[0]
Returns
NULL or identity if success

Definition at line 93 of file n_log.c.

References __n_assert, and proc_name.

Referenced by main().

+ Here is the caller graph for this function:

◆ set_log_file()

int set_log_file ( char *  file)

set a file as standard log output

set a file as standard log output

Parameters
fileThe filename where to log
Returns
TRUE or FALSE

Definition at line 167 of file n_log.c.

References __n_assert, _str, LOG_ERR, LOG_FILE, log_file, n_log, and set_log_level().

Referenced by main(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_log_level()

void set_log_level ( const int  log_level)

Set global log level.

Possible values: NOLOG , NOTICE , VERBOSE , ERROR , DEBUG

Set global log level.

Parameters
log_levelLog level value. Supported: NOLOG,LOG_NOTICE/INFO/ERR/DEBUG,LOG_FILE/STDERR/SYSJRNL

Definition at line 120 of file n_log.c.

References LOG_FILE, log_level, LOG_LEVEL, LOG_STDERR, LOG_SYSJRNL, LOG_TYPE, and terminal_support_colors.

Referenced by main(), main(), main(), process_args(), process_args(), process_args(), and set_log_file().

+ Here is the caller graph for this function:

◆ write_safe_log()

int write_safe_log ( TS_LOG log,
char *  pat,
  ... 
)

write to a thread-safe logging file

Parameters
logA TS_LOG handler
patPattern for writting (i.e "%d %d %s")
Returns
TRUE on success, FALSE on error

Definition at line 451 of file n_log.c.

References TS_LOG::file, and TS_LOG::LOG_MUTEX.

Referenced by main().

+ Here is the caller graph for this function: