Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.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.
 
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
 
int asprintf (char *strp[], const char *fmt,...)
 snprintf from a va_list
 
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 vasprintf (char **strp, const char *fmt, va_list ap)
 snprintf from a va_list, helper for asprintf
 
int write_safe_log (TS_LOG *log, char *pat,...)
 write to a thread-safe logging file
 

Variables

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

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 24 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 154 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 196 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 172 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, ex_gui.c, and ex_gui_particles.c.

Definition at line 54 of file n_log.c.

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

◆ LOG_LEVEL

int LOG_LEVEL = -1
static

static global maximum wanted log level value

Definition at line 48 of file n_log.c.

Referenced by get_log_level(), and set_log_level().

◆ LOG_TYPE

int LOG_TYPE = -4
static

static global logging type ( STDERR, FILE, SYSJRNL )

Definition at line 51 of file n_log.c.

Referenced by _n_log(), and set_log_level().

◆ prioritynames

LOG_LEVELS prioritynames[]
static
Initial value:
=
{
{"EMERG", 0 , "ERROR"},
{"ALERT", 1 , "ERROR"},
{"CRITICAL", 2 , "ERROR"},
{"ERR", 3 , "ERROR"},
{"WARNING", 4 , "WARNING"},
{"NOTICE", 5 , "SUCCESS"},
{"INFO", 6 , "INFORMATION"},
{"DEBUG", 7 , "INFORMATION"},
{NULL, -1, NULL}}

array of log levels

Definition at line 35 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 57 of file n_log.c.

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