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,...)
 Logging function.
 
int close_safe_logging (TS_LOG *log)
 close a thread-safe logging file
 
void close_sysjrnl (void)
 Close syslog connection or clean internals for event log.
 
FILE * get_log_file (void)
 return the current log_file
 
int get_log_level (void)
 Get the global log level value.
 
int open_safe_logging (TS_LOG **log, char *pathname, char *opt)
 Open a thread-safe logging file.
 
char * open_sysjrnl (char *identity)
 Open connection to syslog or create internals for event log.
 
int set_log_file (char *file)
 Set the logging to a file instead of stderr.
 
void set_log_level (const int log_level)
 Set the global log level value ( static int 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 82 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 54 of file n_log.h.

◆ LOG_CRIT

#define LOG_CRIT   2

critical conditions

Examples
ex_log.c.

Definition at line 56 of file n_log.h.

◆ LOG_DEBUG

◆ LOG_EMERG

#define LOG_EMERG   0

system is unusable

Examples
ex_log.c.

Definition at line 52 of file n_log.h.

◆ LOG_ERR

◆ LOG_FILE

#define LOG_FILE   -3

internal, logging to file

Definition at line 29 of file n_log.h.

◆ LOG_INFO

◆ LOG_NOTICE

#define LOG_NOTICE   5

◆ LOG_NULL

#define LOG_NULL   -1

no log output

Examples
ex_common.c, ex_crypto.c, ex_log.c, ex_network.c, ex_network_ssl.c, ex_stack.c, ex_threads.c, and ex_trees.c.

Definition at line 27 of file n_log.h.

◆ LOG_STDERR

#define LOG_STDERR   -4

internal, default LOG_TYPE

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

Definition at line 31 of file n_log.h.

◆ LOG_SYSJRNL

#define LOG_SYSJRNL   100

to sysjrnl

Definition at line 33 of file n_log.h.

◆ LOG_WARNING

#define LOG_WARNING   4

warning conditions

Examples
ex_log.c.

Definition at line 60 of file n_log.h.

◆ n_log

#define n_log (   __LEVEL__,
  ... 
)
Value:
do \
{ \
_n_log( __LEVEL__ , __FILE__ , __func__ , __LINE__ , __VA_ARGS__ ); \
}while( 0 )

Logging function wrapper to get line and func.

Examples
ex_base64.c, ex_common.c, ex_configfile.c, ex_crypto.c, ex_exceptions.c, ex_fluid.c, ex_fluid_config.c, ex_gui.c, ex_gui_dictionary.c, ex_gui_particles.c, ex_hash.c, ex_list.c, ex_log.c, ex_network.c, ex_network_ssl.c, ex_nstr.c, ex_pcre.c, ex_signals.c, ex_stack.c, and ex_threads.c.

Definition at line 74 of file n_log.h.

Function Documentation

◆ _n_log()

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

Logging function.

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

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

Definition at line 234 of file n_log.c.

References FreeNoLog, get_log_level(), log_file, LOG_NULL, LOG_SYSJRNL, LOG_TYPE, Malloc, prioritynames, proc_name, and vasprintf().

Referenced by _n_nodup_log(), and _n_nodup_log_indexed().

+ 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 368 of file n_log.c.

◆ close_sysjrnl()

void close_sysjrnl ( void  )

Close syslog connection or clean internals for event log.

Definition at line 83 of file n_log.c.

References FreeNoLog, and proc_name.

◆ get_log_file()

FILE * get_log_file ( void  )

return the current log_file

Returns
a valid FILE handle or NULL

Definition at line 160 of file n_log.c.

References log_file.

◆ get_log_level()

int get_log_level ( void  )

Get the global log level value.

Returns
static int LOG_LEVEL

Definition at line 123 of file n_log.c.

References LOG_LEVEL.

Referenced by _n_log().

+ 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 298 of file n_log.c.

References Malloc.

◆ open_sysjrnl()

char * open_sysjrnl ( char *  identity)

Open connection to syslog or create internals for event log.

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

Definition at line 64 of file n_log.c.

References __n_assert, and proc_name.

◆ set_log_file()

int set_log_file ( char *  file)

Set the logging to a file instead of stderr.

Parameters
fileThe filename where to log
Returns
TRUE or FALSE

Definition at line 135 of file n_log.c.

References __n_assert, LOG_FILE, log_file, and set_log_level().

+ Here is the call graph for this function:

◆ set_log_level()

void set_log_level ( const int  log_level)

Set the global log level value ( static int LOG_LEVEL )

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

Definition at line 97 of file n_log.c.

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

Referenced by 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 337 of file n_log.c.