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 130
 #ifdef NO_LOG
126 131
 
127 132
 #	ifdef __SUNPRO_C
128
-#		define LOG_(level, prefix, fmt, ...)
133
+#		define LOG_(facility, level, prefix, fmt, ...)
129 134
 #		define LOG(level, fmt, ...)
135
+#		define LOG_FC(facility, level, fmt, ...)
130 136
 #	else
131
-#		define LOG_(level, prefix, fmt, args...)
137
+#		define LOG_(facility, level, prefix, fmt, args...)
132 138
 #		define LOG(level, fmt, args...)
139
+#		define LOG_FC(facility, level, fmt, args...)
133 140
 #	endif
134 141
 
135 142
 #else
... ...
@@ -145,7 +152,7 @@ int log_facility_fixup(void *handle, str *name, void **val);
145 152
 #	endif
146 153
 
147 154
 #	ifdef __SUNPRO_C
148
-#		define LOG_(level, prefix, fmt, ...) \
155
+#		define LOG_(facility, level, prefix, fmt, ...) \
149 156
 			do { \
150 157
 				if (unlikely(cfg_get(core, core_cfg, debug) >= (level) && \
151 158
 						DPRINT_NON_CRIT)) { \
... ...
@@ -158,7 +165,9 @@ int log_facility_fixup(void *handle, str *name, void **val);
158 165
 									__VA_ARGS__); \
159 166
 						} else { \
160 167
 							syslog(LOG2SYSLOG_LEVEL(level) | \
161
-									cfg_get(core, core_cfg, log_facility),\
168
+								   (((facility) != DEFAULT_FACILITY) ? \
169
+									(facility) : \
170
+									cfg_get(core, core_cfg, log_facility)), \
162 171
 									"%s: %s" fmt, LOG_LEVEL2NAME(level),\
163 172
 									(prefix), __VA_ARGS__); \
164 173
 						} \
... ...
@@ -170,22 +179,29 @@ int log_facility_fixup(void *handle, str *name, void **val);
170 179
 						} else { \
171 180
 							if ((level)<L_ALERT) \
172 181
 								syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \
173
-										cfg_get(core, core_cfg, log_facility),\
174
-										"%s" fmt, (prefix), __VA_ARGS__); \
182
+									   (((facility) != DEFAULT_FACILITY) ? \
183
+										(facility) : \
184
+										cfg_get(core, core_cfg, log_facility)),\
185
+									   "%s" fmt, (prefix), __VA_ARGS__); \
175 186
 							else \
176 187
 								syslog(LOG2SYSLOG_LEVEL(L_DBG) | \
177
-										cfg_get(core, core_cfg, log_facility),\
178
-										"%s" fmt, (prefix), __VA_ARGS__); \
188
+									   (((facility) != DEFAULT_FACILITY) ? \
189
+										(facility) : \
190
+										cfg_get(core, core_cfg, log_facility)),\
191
+									   "%s" fmt, (prefix), __VA_ARGS__); \
179 192
 						} \
180 193
 					} \
181 194
 					DPRINT_CRIT_EXIT; \
182 195
 				} \
183 196
 			} while(0)
184 197
 			
185
-#		define LOG(level, fmt, ...)  LOG_((level), LOC_INFO, fmt, __VA_ARGS__)
198
+#		define LOG(level, fmt, ...) \
199
+	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, __VA_ARGS__)
200
+#		define LOG_FC(facility, level, fmt, ...) \
201
+	LOG_((facility), (level), LOC_INFO, fmt, __VA_ARGS__)
186 202
 
187 203
 #	else /* ! __SUNPRO_C */
188
-#		define LOG_(level, prefix, fmt, args...) \
204
+#		define LOG_(facility, level, prefix, fmt, args...) \
189 205
 			do { \
190 206
 				if (cfg_get(core, core_cfg, debug) >= (level) && \
191 207
 						DPRINT_NON_CRIT) { \
... ...
@@ -197,7 +213,9 @@ int log_facility_fixup(void *handle, str *name, void **val);
197 213
 									LOG_LEVEL2NAME(level),(prefix), ## args);\
198 214
 						} else { \
199 215
 							syslog(LOG2SYSLOG_LEVEL(level) |\
200
-									cfg_get(core, core_cfg, log_facility), \
216
+								   (((facility) != DEFAULT_FACILITY) ? \
217
+									(facility) : \
218
+									cfg_get(core, core_cfg, log_facility)), \
201 219
 									"%s: %s" fmt, LOG_LEVEL2NAME(level),\
202 220
 									(prefix), ## args); \
203 221
 						} \
... ...
@@ -209,11 +227,15 @@ int log_facility_fixup(void *handle, str *name, void **val);
209 227
 						} else { \
210 228
 							if ((level)<L_ALERT) \
211 229
 								syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \
212
-										cfg_get(core, core_cfg, log_facility),\
230
+									   (((facility) != DEFAULT_FACILITY) ? \
231
+										(facility) : \
232
+										cfg_get(core, core_cfg, log_facility)),\
213 233
 										"%s" fmt, (prefix), ## args); \
214 234
 							else \
215 235
 								syslog(LOG2SYSLOG_LEVEL(L_DBG) | \
216
-										cfg_get(core, core_cfg, log_facility),\
236
+									   (((facility) != DEFAULT_FACILITY) ? \
237
+										(facility) : \
238
+										cfg_get(core, core_cfg, log_facility)),\
217 239
 										"%s" fmt, (prefix), ## args); \
218 240
 						} \
219 241
 					} \
... ...
@@ -221,7 +243,10 @@ int log_facility_fixup(void *handle, str *name, void **val);
221 243
 				} \
222 244
 			} while(0)
223 245
 			
224
-#		define LOG(level, fmt, args...)  LOG_((level), LOC_INFO, fmt, ## args)
246
+#		define LOG(level, fmt, args...) \
247
+	LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, ## args)
248
+#		define LOG_FC(facility, level, fmt, args...) \
249
+	LOG_((facility), (level), LOC_INFO, fmt, ## args)
225 250
 		
226 251
 #	endif /* __SUNPRO_C */
227 252
 #endif /* NO_LOG */
... ...
@@ -272,7 +297,7 @@ int log_facility_fixup(void *handle, str *name, void **val);
272 297
 /* kamailio/openser compatibility */
273 298
 
274 299
 #define LM_GEN1 LOG
275
-
300
+#define LM_GEN2 LOG_FC
276 301
 #define LM_ALERT ALERT
277 302
 #define LM_CRIT  CRIT
278 303
 #define LM_ERR ERR