Browse code

core: added framework to allow replacing logging to syslog

- this enables a module to replace all logging to syslog with another
logging mechanism
- it is not enabled when log_stderror=yes or the system is detected as
__SUNPRO_C

Daniel-Constantin Mierla authored on 21/10/2015 07:44:25
Showing 2 changed files
... ...
@@ -36,6 +36,19 @@
36 36
 #include <stdio.h>
37 37
 #include <strings.h>
38 38
 
39
+char *_km_log_engine_type = NULL;
40
+char *_km_log_engine_data = NULL;
41
+
42
+km_log_f _km_log_func = &syslog;
43
+
44
+/**
45
+ *
46
+ */
47
+void km_log_func_set(km_log_f f)
48
+{
49
+	_km_log_func = f;
50
+}
51
+
39 52
 #ifndef NO_SIG_DEBUG
40 53
 /* signal protection: !=0 when LOG/DBG/... are printing */
41 54
 volatile int dprint_crit = 0; 
... ...
@@ -123,6 +123,13 @@ extern int log_stderr;
123 123
 extern int log_color;
124 124
 extern char *log_prefix_fmt;
125 125
 extern str *log_prefix_val;
126
+extern char *_km_log_engine_type;
127
+extern char *_km_log_engine_data;
128
+
129
+typedef void (*km_log_f)(int, const char *, ...);
130
+extern km_log_f _km_log_func;
131
+
132
+void km_log_func_set(km_log_f f);
126 133
 
127 134
 /** @brief maps log levels to their string name and corresponding syslog level */
128 135
 
... ...
@@ -303,7 +310,7 @@ void log_prefix_init(void);
303 303
 						if (unlikely(log_color)) dprint_color_reset(); \
304 304
 					} else { \
305 305
 						if(unlikely(log_prefix_val)) { \
306
-							syslog(LOG2SYSLOG_LEVEL(__llevel) |\
306
+							_km_log_func(LOG2SYSLOG_LEVEL(__llevel) |\
307 307
 							   (((facility) != DEFAULT_FACILITY) ? \
308 308
 								(facility) : \
309 309
 								get_debug_facility(LOG_MNAME, LOG_MNAME_LEN)), \
... ...
@@ -312,7 +319,7 @@ void log_prefix_init(void);
312 312
 								(lname)?(lname):LOG_LEVEL2NAME(__llevel),\
313 313
 								(prefix) , ## args); \
314 314
 						} else { \
315
-							syslog(LOG2SYSLOG_LEVEL(__llevel) |\
315
+							_km_log_func(LOG2SYSLOG_LEVEL(__llevel) |\
316 316
 							   (((facility) != DEFAULT_FACILITY) ? \
317 317
 								(facility) : \
318 318
 								get_debug_facility(LOG_MNAME, LOG_MNAME_LEN)), \