Browse code

Add the possibility to override logging facility.

This patch adds adds a new parameter to LOG_ which makes it possible to
override the logging facility configured through the config framework.
Modules then can opt to specify a different logging facility than the
one configured globally in the sip router. The is currently used by the
acc module from kamailio.

The first parameter of LOG_ is now facility. You can set the parameter
to DEFAULT_FACILITY and in that case the facility configured through
the config framework of the sip router will be used.

The value of DEFAULT_FACILITY is 0 which is equal to LOG_KERN on linux
systems. This means that you cannot set the logging facility to
LOG_KERN from modules calling LOG_ directly because then the logging
facility configured through the config framework will be used.

This patch also adds a new macro called LOG_FC which works just like
LOG macro except that the first parameter of LOG_FC is the logging
facility to be used.

And finally there is a new macro called LM_GEN2, this is one of the
kamailio compatibility macros and it is just a different name for
LOG_FC.

Signed-off-by: Jan Janak <jan@iptel.org>

Jan Janak authored on 02/03/2009 16:23:17
Showing 1 changed files
... ...
@@ -81,6 +81,11 @@
81 81
 #define L_INFO   	2
82 82
 #define L_DBG    	3
83 83
 
84
+/* This is the facility value used to indicate that the caller of the macro
85
+ * did not override the facility. Value 0 (the defaul) is LOG_KERN on Linux
86
+ */
87
+#define DEFAULT_FACILITY 0
88
+
84 89
 #define LOG_LEVEL2NAME(level)	(log_level_info[(level) - (L_ALERT)].name)
85 90
 #define LOG2SYSLOG_LEVEL(level) \
86 91
 	(log_level_info[(level) - (L_ALERT)].syslog_level)
... ...
@@ -125,11 +130,13 @@ int log_facility_fixup(void *handle, str *name, void **val);
125 125
 #ifdef NO_LOG
126 126
 
127 127
 #	ifdef __SUNPRO_C
128
-#		define LOG_(level, prefix, fmt, ...)
128
+#		define LOG_(facility, level, prefix, fmt, ...)
129 129
 #		define LOG(level, fmt, ...)
130
+#		define LOG_FC(facility, level, fmt, ...)
130 131
 #	else
131
-#		define LOG_(level, prefix, fmt, args...)
132
+#		define LOG_(facility, level, prefix, fmt, args...)
132 133
 #		define LOG(level, fmt, args...)
134
+#		define LOG_FC(facility, level, fmt, args...)
133 135
 #	endif
134 136
 
135 137
 #else
... ...
@@ -145,7 +152,7 @@ int log_facility_fixup(void *handle, str *name, void **val);
145 145
 #	endif
146 146
 
147 147
 #	ifdef __SUNPRO_C
148
-#		define LOG_(level, prefix, fmt, ...) \
148
+#		define LOG_(facility, level, prefix, fmt, ...) \
149 149
 			do { \
150 150
 				if (unlikely(cfg_get(core, core_cfg, debug) >= (level) && \
151 151
 						DPRINT_NON_CRIT)) { \
... ...
@@ -158,7 +165,9 @@ int log_facility_fixup(void *handle, str *name, void **val);
158 158
 									__VA_ARGS__); \
159 159
 						} else { \
160 160
 							syslog(LOG2SYSLOG_LEVEL(level) | \
161
-									cfg_get(core, core_cfg, log_facility),\
161
+								   (((facility) != DEFAULT_FACILITY) ? \
162
+									(facility) : \
163
+									cfg_get(core, core_cfg, log_facility)), \
162 164
 									"%s: %s" fmt, LOG_LEVEL2NAME(level),\
163 165
 									(prefix), __VA_ARGS__); \
164 166
 						} \
... ...
@@ -170,22 +179,29 @@ int log_facility_fixup(void *handle, str *name, void **val);
170 170
 						} else { \
171 171
 							if ((level)<L_ALERT) \
172 172
 								syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \
173
-										cfg_get(core, core_cfg, log_facility),\
174
-										"%s" fmt, (prefix), __VA_ARGS__); \
173
+									   (((facility) != DEFAULT_FACILITY) ? \
174
+										(facility) : \
175
+										cfg_get(core, core_cfg, log_facility)),\
176
+									   "%s" fmt, (prefix), __VA_ARGS__); \
175 177
 							else \
176 178
 								syslog(LOG2SYSLOG_LEVEL(L_DBG) | \
177
-										cfg_get(core, core_cfg, log_facility),\
178
-										"%s" fmt, (prefix), __VA_ARGS__); \
179
+									   (((facility) != DEFAULT_FACILITY) ? \
180
+										(facility) : \
181
+										cfg_get(core, core_cfg, log_facility)),\
182
+									   "%s" fmt, (prefix), __VA_ARGS__); \
179 183
 						} \
180 184
 					} \
181 185
 					DPRINT_CRIT_EXIT; \
182 186
 				} \
183 187
 			} while(0)
184 188
 			
185
-#		define LOG(level, fmt, ...)  LOG_((level), LOC_INFO, fmt, __VA_ARGS__)
189
+#		define LOG(level, fmt, ...) \
190
+	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, __VA_ARGS__)
191
+#		define LOG_FC(facility, level, fmt, ...) \
192
+	LOG_((facility), (level), LOC_INFO, fmt, __VA_ARGS__)
186 193
 
187 194
 #	else /* ! __SUNPRO_C */
188
-#		define LOG_(level, prefix, fmt, args...) \
195
+#		define LOG_(facility, level, prefix, fmt, args...) \
189 196
 			do { \
190 197
 				if (cfg_get(core, core_cfg, debug) >= (level) && \
191 198
 						DPRINT_NON_CRIT) { \
... ...
@@ -197,7 +213,9 @@ int log_facility_fixup(void *handle, str *name, void **val);
197 197
 									LOG_LEVEL2NAME(level),(prefix), ## args);\
198 198
 						} else { \
199 199
 							syslog(LOG2SYSLOG_LEVEL(level) |\
200
-									cfg_get(core, core_cfg, log_facility), \
200
+								   (((facility) != DEFAULT_FACILITY) ? \
201
+									(facility) : \
202
+									cfg_get(core, core_cfg, log_facility)), \
201 203
 									"%s: %s" fmt, LOG_LEVEL2NAME(level),\
202 204
 									(prefix), ## args); \
203 205
 						} \
... ...
@@ -209,11 +227,15 @@ int log_facility_fixup(void *handle, str *name, void **val);
209 209
 						} else { \
210 210
 							if ((level)<L_ALERT) \
211 211
 								syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \
212
-										cfg_get(core, core_cfg, log_facility),\
212
+									   (((facility) != DEFAULT_FACILITY) ? \
213
+										(facility) : \
214
+										cfg_get(core, core_cfg, log_facility)),\
213 215
 										"%s" fmt, (prefix), ## args); \
214 216
 							else \
215 217
 								syslog(LOG2SYSLOG_LEVEL(L_DBG) | \
216
-										cfg_get(core, core_cfg, log_facility),\
218
+									   (((facility) != DEFAULT_FACILITY) ? \
219
+										(facility) : \
220
+										cfg_get(core, core_cfg, log_facility)),\
217 221
 										"%s" fmt, (prefix), ## args); \
218 222
 						} \
219 223
 					} \
... ...
@@ -221,7 +243,10 @@ int log_facility_fixup(void *handle, str *name, void **val);
221 221
 				} \
222 222
 			} while(0)
223 223
 			
224
-#		define LOG(level, fmt, args...)  LOG_((level), LOC_INFO, fmt, ## args)
224
+#		define LOG(level, fmt, args...) \
225
+	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, ## args)
226
+#		define LOG_FC(facility, level, fmt, args...) \
227
+	LOG_((facility), (level), LOC_INFO, fmt, ## args)
225 228
 		
226 229
 #	endif /* __SUNPRO_C */
227 230
 #endif /* NO_LOG */
... ...
@@ -272,7 +297,7 @@ int log_facility_fixup(void *handle, str *name, void **val);
272 272
 /* kamailio/openser compatibility */
273 273
 
274 274
 #define LM_GEN1 LOG
275
-
275
+#define LM_GEN2 LOG_FC
276 276
 #define LM_ALERT ALERT
277 277
 #define LM_CRIT  CRIT
278 278
 #define LM_ERR ERR