Nilorea Library
C utilities for networking, threading, graphics
n_log.h
Go to the documentation of this file.
1
7#ifndef __LOG_HEADER_GUARD__
8#define __LOG_HEADER_GUARD__
9
10#ifdef __cplusplus
11extern "C"
12{
13#endif
14
20#include <stdio.h>
21#include <stdlib.h>
22#include <sys/stat.h>
23#include <pthread.h>
24#include "n_common.h"
25
27#define LOG_NULL -1
29#define LOG_FILE -3
31#define LOG_STDERR -4
33#define LOG_SYSJRNL 100
34
35#if defined( __linux__ ) || defined( __sun )
36
37#include <syslog.h>
38#include <pthread.h>
39
40#ifdef __sun
41#include <sys/varargs.h>
42#else
43#include <stdarg.h>
44#endif
45
46#else
47
48#include <stdarg.h>
49
50
52#define LOG_EMERG 0
54#define LOG_ALERT 1
56#define LOG_CRIT 2
58#define LOG_ERR 3
60#define LOG_WARNING 4
62#define LOG_NOTICE 5
64#define LOG_INFO 6
66#define LOG_DEBUG 7
67
68
69#endif
70
71
72
74#define n_log( __LEVEL__ , ... ) \
75 do \
76 { \
77 _n_log( __LEVEL__ , __FILE__ , __func__ , __LINE__ , __VA_ARGS__ ); \
78 }while( 0 )
79
80
82typedef struct TS_LOG
83{
85 pthread_mutex_t LOG_MUTEX;
87 FILE *file;
88} TS_LOG;
89
90/* Open a syslog / set name for event log */
91char *open_sysjrnl( char *identity );
92/* close syslog / free name for event log */
93void close_sysjrnl( void );
94/* Set global log level. Possible values: NOLOG , NOTICE , VERBOSE , ERROR , DEBUG */
95void set_log_level( const int log_level );
96/* Return the global log level. Possible values: NOLOG , NOTICE , VERBOSE , ERROR , DEBUG */
97int get_log_level( void );
98/* set a file as standard log output */
99int set_log_file( char *file );
100/* get the log gile name if any */
101FILE *get_log_file( void );
102/* Full log function. Muste be wrapped in a MACRO to get the correct file-func-line informations */
103void _n_log( int level, const char *file, const char *func, int line, const char *format, ... ) ;
104
105
106/* Open a thread-safe logging file */
107int open_safe_logging( TS_LOG **log, char *pathname, char *opt );
108/* write to a thread-safe logging file */
109int write_safe_log( TS_LOG *log, char *pat, ... );
110/* close a thread-safe logging file */
111int close_safe_logging( TS_LOG *log );
112
117#ifdef __cplusplus
118}
119#endif
120#endif
pthread_mutex_t LOG_MUTEX
mutex for thread-safe writting
Definition: n_log.h:85
FILE * file
File handler.
Definition: n_log.h:87
FILE * get_log_file(void)
return the current log_file
Definition: n_log.c:160
int write_safe_log(TS_LOG *log, char *pat,...)
write to a thread-safe logging file
Definition: n_log.c:337
int open_safe_logging(TS_LOG **log, char *pathname, char *opt)
Open a thread-safe logging file.
Definition: n_log.c:298
char * open_sysjrnl(char *identity)
Open connection to syslog or create internals for event log.
Definition: n_log.c:64
void close_sysjrnl(void)
Close syslog connection or clean internals for event log.
Definition: n_log.c:83
int close_safe_logging(TS_LOG *log)
close a thread-safe logging file
Definition: n_log.c:368
int set_log_file(char *file)
Set the logging to a file instead of stderr.
Definition: n_log.c:135
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
Definition: n_log.c:97
void _n_log(int level, const char *file, const char *func, int line, const char *format,...)
Logging function.
Definition: n_log.c:234
int get_log_level(void)
Get the global log level value.
Definition: n_log.c:123
ThreadSafe LOGging structure.
Definition: n_log.h:83
Common headers and low-level hugly functions & define.