Nilorea Library
C utilities for networking, threading, graphics
n_log.c File Reference

generic logging system More...

#include "nilorea/n_common.h"
#include "nilorea/n_log.h"
#include <pthread.h>
#include <string.h>
#include <inttypes.h>
#include <syslog.h>
+ Include dependency graph for n_log.c:

Go to the source code of this file.

Data Structures

struct  LOG_LEVELS
 internal struct to handle log types More...
 

Functions

void _n_log (int level, const char *file, const char *func, int line, const char *format,...)
 Logging function. More...
 
int _vscprintf_so (const char *format, va_list pargs)
 compute the size of a string made with format 'fmt' and arguments in the va_list 'ap', helper for vasprintf More...
 
int asprintf (char *strp[], const char *fmt,...)
 snprintf from a va_list More...
 
int close_safe_logging (TS_LOG *log)
 close a thread-safe logging file More...
 
void close_sysjrnl (void)
 Close syslog connection or clean internals for event log. More...
 
FILE * get_log_file (void)
 return the current log_file More...
 
int get_log_level (void)
 Get the global log level value. More...
 
int open_safe_logging (TS_LOG **log, char *pathname, char *opt)
 Open a thread-safe logging file. More...
 
char * open_sysjrnl (char *identity)
 Open connection to syslog or create internals for event log. More...
 
int set_log_file (char *file)
 Set the logging to a file instead of stderr. More...
 
void set_log_level (const int log_level)
 Set the global log level value ( static int LOG_LEVEL ) More...
 
int vasprintf (char **strp, const char *fmt, va_list ap)
 snprintf from a va_list, helper for asprintf More...
 
int write_safe_log (TS_LOG *log, char *pat,...)
 write to a thread-safe logging file More...
 

Variables

static FILE * log_file = NULL
 static FILE handling if logging to file is enabled More...
 
static int LOG_LEVEL = LOG_NULL
 static global maximum wanted log level value More...
 
static int LOG_TYPE = LOG_STDERR
 static global logging type ( STDERR, FILE, SYSJRNL ) More...
 
static LOG_LEVELS prioritynames []
 array of log levels More...
 
char * proc_name = NULL
 static proc name, for windows event log More...
 

Detailed Description

generic logging system

Author
Castagnier Mickael
Date
2013-03-12

Definition in file n_log.c.


Data Structure Documentation

◆ LOG_LEVELS

struct LOG_LEVELS

internal struct to handle log types

Definition at line 21 of file n_log.c.

+ Collaboration diagram for LOG_LEVELS:
Data Fields
char * c_name string of log type
int c_val numeric value of log type
char * w_name event log value

Function Documentation

◆ _vscprintf_so()

int _vscprintf_so ( const char *  format,
va_list  pargs 
)

compute the size of a string made with format 'fmt' and arguments in the va_list 'ap', helper for vasprintf

Parameters
formatformat to pass to printf
pargsva_list to use as printf parameter
Returns
-1 or the size of the string

Definition at line 172 of file n_log.c.

Referenced by vasprintf().

+ Here is the caller graph for this function:

◆ asprintf()

int asprintf ( char *  strp[],
const char *  fmt,
  ... 
)

snprintf from a va_list

Parameters
strpstring holding the result
fmtformat to pass to printf
...list of format parameters
Returns
-1 or the size of the string

Definition at line 216 of file n_log.c.

References vasprintf().

+ Here is the call graph for this function:

◆ vasprintf()

int vasprintf ( char **  strp,
const char *  fmt,
va_list  ap 
)

snprintf from a va_list, helper for asprintf

Parameters
strpstring holding the result
fmtformat to pass to printf
apva_list to use as printf parameter
Returns
-1 or the size of the string

Definition at line 191 of file n_log.c.

References _vscprintf_so(), and Malloc.

Referenced by _n_log(), _n_nodup_log(), _n_nodup_log_indexed(), and asprintf().

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

Variable Documentation

◆ log_file

FILE* log_file = NULL
static

static FILE handling if logging to file is enabled

Examples
ex_fluid.c, and ex_gui_particles.c.

Definition at line 53 of file n_log.c.

Referenced by _n_log(), get_log_file(), and set_log_file().

◆ LOG_LEVEL

int LOG_LEVEL = LOG_NULL
static

static global maximum wanted log level value

Definition at line 47 of file n_log.c.

Referenced by get_log_level(), and set_log_level().

◆ LOG_TYPE

int LOG_TYPE = LOG_STDERR
static

static global logging type ( STDERR, FILE, SYSJRNL )

Definition at line 50 of file n_log.c.

Referenced by _n_log(), and set_log_level().

◆ prioritynames

LOG_LEVELS prioritynames[]
static
Initial value:
=
{
{ "EMERG", LOG_EMERG, "ERROR" },
{ "ALERT", LOG_ALERT, "ERROR" },
{ "CRITICAL", LOG_CRIT, "ERROR" },
{ "ERR", LOG_ERR, "ERROR" },
{ "WARNING", LOG_WARNING, "WARNING" },
{ "NOTICE", LOG_NOTICE, "SUCCESS" },
{ "INFO", LOG_INFO, "INFORMATION" },
{ "DEBUG", LOG_DEBUG, "INFORMATION" },
{ NULL, -1, NULL }
}
#define LOG_ALERT
action must be taken immediately
Definition: n_log.h:54
#define LOG_EMERG
system is unusable
Definition: n_log.h:52
#define LOG_DEBUG
debug-level messages
Definition: n_log.h:66
#define LOG_ERR
error conditions
Definition: n_log.h:58
#define LOG_CRIT
critical conditions
Definition: n_log.h:56
#define LOG_NOTICE
normal but significant condition
Definition: n_log.h:62
#define LOG_WARNING
warning conditions
Definition: n_log.h:60
#define LOG_INFO
informational
Definition: n_log.h:64

array of log levels

Definition at line 33 of file n_log.c.

Referenced by _n_log().

◆ proc_name

char* proc_name = NULL

static proc name, for windows event log

Definition at line 56 of file n_log.c.

Referenced by _n_log(), close_sysjrnl(), and open_sysjrnl().