Pārlūkot izejas kodu

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 10 gadi atpakaļ
vecāks
revīzija
d20cc8bea3
2 mainītis faili ar 22 papildinājumiem un 2 dzēšanām
  1. 13 0
      dprint.c
  2. 9 2
      dprint.h

+ 13 - 0
dprint.c

@@ -36,6 +36,19 @@
 #include <stdio.h>
 #include <strings.h>
 
+char *_km_log_engine_type = NULL;
+char *_km_log_engine_data = NULL;
+
+km_log_f _km_log_func = &syslog;
+
+/**
+ *
+ */
+void km_log_func_set(km_log_f f)
+{
+	_km_log_func = f;
+}
+
 #ifndef NO_SIG_DEBUG
 /* signal protection: !=0 when LOG/DBG/... are printing */
 volatile int dprint_crit = 0; 

+ 9 - 2
dprint.h

@@ -123,6 +123,13 @@ extern int log_stderr;
 extern int log_color;
 extern char *log_prefix_fmt;
 extern str *log_prefix_val;
+extern char *_km_log_engine_type;
+extern char *_km_log_engine_data;
+
+typedef void (*km_log_f)(int, const char *, ...);
+extern km_log_f _km_log_func;
+
+void km_log_func_set(km_log_f f);
 
 /** @brief maps log levels to their string name and corresponding syslog level */
 
@@ -303,7 +310,7 @@ void log_prefix_init(void);
 						if (unlikely(log_color)) dprint_color_reset(); \
 					} else { \
 						if(unlikely(log_prefix_val)) { \
-							syslog(LOG2SYSLOG_LEVEL(__llevel) |\
+							_km_log_func(LOG2SYSLOG_LEVEL(__llevel) |\
 							   (((facility) != DEFAULT_FACILITY) ? \
 								(facility) : \
 								get_debug_facility(LOG_MNAME, LOG_MNAME_LEN)), \
@@ -312,7 +319,7 @@ void log_prefix_init(void);
 								(lname)?(lname):LOG_LEVEL2NAME(__llevel),\
 								(prefix) , ## args); \
 						} else { \
-							syslog(LOG2SYSLOG_LEVEL(__llevel) |\
+							_km_log_func(LOG2SYSLOG_LEVEL(__llevel) |\
 							   (((facility) != DEFAULT_FACILITY) ? \
 								(facility) : \
 								get_debug_facility(LOG_MNAME, LOG_MNAME_LEN)), \