Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros Groups
n_log.h
Go to the documentation of this file.
1 /*\file n_log.h
2 * generic log system
3 *\author Mickael Castagnier
4 *\date 2013-04-15
5 */
6 #ifndef __LOG_HEADER_GUARD__
7 #define __LOG_HEADER_GUARD__
8
9 #ifdef __cplusplus
10 extern "C"
11 {
12 #endif
13
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <sys/stat.h>
22 #include "n_common.h"
23
24 #if defined( LINUX ) || defined( SOLARIS )
25 #include <sysjrnl.h>
26 #endif
27
29 #define NOLOG -1
30
32 #define SYSJRNL -2
33
34 #if defined( LINUX ) || defined( SOLARIS )
35
36 #include <syslog.h>
37 #include <pthread.h>
38
39 #ifdef SOLARIS
40 #include <sys/varargs.h>
41 #else
42 #include <stdarg.h>
43 #endif
44
45 #else
46
47 #include <stdarg.h>
48 #include <pthread.h>
49
51 #define LOG_EMERG 0
52
53 #define LOG_ALERT 1
54
55 #define LOG_CRIT 2
56
57 #define LOG_ERR 3
58
59 #define LOG_WARNING 4
60
61 #define LOG_NOTICE 5
62
63 #define LOG_INFO 6
64
65 #define LOG_DEBUG 7
66
67 #endif
68
69
70
72 #define n_log( __LEVEL__ , ... ) \
73 do \
74 { \
75 _n_log( __LEVEL__ , __FILE__ , __func__ , __LINE__ , __VA_ARGS__ ); \
76 }while( 0 )
77
78
80 typedef struct TS_LOG
81 {
83 pthread_mutex_t LOG_MUTEX;
85 FILE *file;
86 } TS_LOG;
87
88
89 /* Set global log level. Possible values: NOLOG , NOTICE , VERBOSE , ERROR , DEBUG */
90 void set_log_level( const int log_level );
91 /* Return the global log level. Possible values: NOLOG , NOTICE , VERBOSE , ERROR , DEBUG */
92 int get_log_level();
93 /* set a file as standard log output */
94 int set_log_file( char *file );
95 /* get the log gile name if any */
96 FILE *get_log_file();
97 /* Full log function. Muste be wrapped in a MACRO to get the correct file-func-line informations */
98 void _n_log( int level , const char *file , const char *func , int line , const char *format , ... ) ;
99
100
101 /* Open a thread-safe logging file */
102 int open_safe_logging( TS_LOG **log , char *pathname , char *opt );
103 /* write to a thread-safe logging file */
104 int write_safe_log( TS_LOG *log , char *pat , ... );
105 /* close a thread-safe logging file */
106 int close_safe_logging( TS_LOG *log );
107
110 #ifdef __cplusplus
111 }
112 #endif
113 #endif