Module: sip-router Branch: master Commit: f5618c1a54e9190bda9057f07caf700d0c96ca65 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f5618c1a...
Author: Jan Janak jan@iptel.org Committer: Jan Janak jan@iptel.org Date: Mon Mar 2 17:23:17 2009 +0100
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
---
dprint.h | 55 ++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/dprint.h b/dprint.h index 12521f5..842cba8 100644 --- a/dprint.h +++ b/dprint.h @@ -81,6 +81,11 @@ #define L_INFO 2 #define L_DBG 3
+/* This is the facility value used to indicate that the caller of the macro + * did not override the facility. Value 0 (the defaul) is LOG_KERN on Linux + */ +#define DEFAULT_FACILITY 0 + #define LOG_LEVEL2NAME(level) (log_level_info[(level) - (L_ALERT)].name) #define LOG2SYSLOG_LEVEL(level) \ (log_level_info[(level) - (L_ALERT)].syslog_level) @@ -125,11 +130,13 @@ int log_facility_fixup(void *handle, str *name, void **val); #ifdef NO_LOG
# ifdef __SUNPRO_C -# define LOG_(level, prefix, fmt, ...) +# define LOG_(facility, level, prefix, fmt, ...) # define LOG(level, fmt, ...) +# define LOG_FC(facility, level, fmt, ...) # else -# define LOG_(level, prefix, fmt, args...) +# define LOG_(facility, level, prefix, fmt, args...) # define LOG(level, fmt, args...) +# define LOG_FC(facility, level, fmt, args...) # endif
#else @@ -145,7 +152,7 @@ int log_facility_fixup(void *handle, str *name, void **val); # endif
# ifdef __SUNPRO_C -# define LOG_(level, prefix, fmt, ...) \ +# define LOG_(facility, level, prefix, fmt, ...) \ do { \ if (unlikely(cfg_get(core, core_cfg, debug) >= (level) && \ DPRINT_NON_CRIT)) { \ @@ -158,7 +165,9 @@ int log_facility_fixup(void *handle, str *name, void **val); __VA_ARGS__); \ } else { \ syslog(LOG2SYSLOG_LEVEL(level) | \ - cfg_get(core, core_cfg, log_facility),\ + (((facility) != DEFAULT_FACILITY) ? \ + (facility) : \ + cfg_get(core, core_cfg, log_facility)), \ "%s: %s" fmt, LOG_LEVEL2NAME(level),\ (prefix), __VA_ARGS__); \ } \ @@ -170,22 +179,29 @@ int log_facility_fixup(void *handle, str *name, void **val); } else { \ if ((level)<L_ALERT) \ syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \ - cfg_get(core, core_cfg, log_facility),\ - "%s" fmt, (prefix), __VA_ARGS__); \ + (((facility) != DEFAULT_FACILITY) ? \ + (facility) : \ + cfg_get(core, core_cfg, log_facility)),\ + "%s" fmt, (prefix), __VA_ARGS__); \ else \ syslog(LOG2SYSLOG_LEVEL(L_DBG) | \ - cfg_get(core, core_cfg, log_facility),\ - "%s" fmt, (prefix), __VA_ARGS__); \ + (((facility) != DEFAULT_FACILITY) ? \ + (facility) : \ + cfg_get(core, core_cfg, log_facility)),\ + "%s" fmt, (prefix), __VA_ARGS__); \ } \ } \ DPRINT_CRIT_EXIT; \ } \ } while(0) -# define LOG(level, fmt, ...) LOG_((level), LOC_INFO, fmt, __VA_ARGS__) +# define LOG(level, fmt, ...) \ + LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, __VA_ARGS__) +# define LOG_FC(facility, level, fmt, ...) \ + LOG_((facility), (level), LOC_INFO, fmt, __VA_ARGS__)
# else /* ! __SUNPRO_C */ -# define LOG_(level, prefix, fmt, args...) \ +# define LOG_(facility, level, prefix, fmt, args...) \ do { \ if (cfg_get(core, core_cfg, debug) >= (level) && \ DPRINT_NON_CRIT) { \ @@ -197,7 +213,9 @@ int log_facility_fixup(void *handle, str *name, void **val); LOG_LEVEL2NAME(level),(prefix), ## args);\ } else { \ syslog(LOG2SYSLOG_LEVEL(level) |\ - cfg_get(core, core_cfg, log_facility), \ + (((facility) != DEFAULT_FACILITY) ? \ + (facility) : \ + cfg_get(core, core_cfg, log_facility)), \ "%s: %s" fmt, LOG_LEVEL2NAME(level),\ (prefix), ## args); \ } \ @@ -209,11 +227,15 @@ int log_facility_fixup(void *handle, str *name, void **val); } else { \ if ((level)<L_ALERT) \ syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \ - cfg_get(core, core_cfg, log_facility),\ + (((facility) != DEFAULT_FACILITY) ? \ + (facility) : \ + cfg_get(core, core_cfg, log_facility)),\ "%s" fmt, (prefix), ## args); \ else \ syslog(LOG2SYSLOG_LEVEL(L_DBG) | \ - cfg_get(core, core_cfg, log_facility),\ + (((facility) != DEFAULT_FACILITY) ? \ + (facility) : \ + cfg_get(core, core_cfg, log_facility)),\ "%s" fmt, (prefix), ## args); \ } \ } \ @@ -221,7 +243,10 @@ int log_facility_fixup(void *handle, str *name, void **val); } \ } while(0) -# define LOG(level, fmt, args...) LOG_((level), LOC_INFO, fmt, ## args) +# define LOG(level, fmt, args...) \ + LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, ## args) +# define LOG_FC(facility, level, fmt, args...) \ + LOG_((facility), (level), LOC_INFO, fmt, ## args) # endif /* __SUNPRO_C */ #endif /* NO_LOG */ @@ -272,7 +297,7 @@ int log_facility_fixup(void *handle, str *name, void **val); /* kamailio/openser compatibility */
#define LM_GEN1 LOG - +#define LM_GEN2 LOG_FC #define LM_ALERT ALERT #define LM_CRIT CRIT #define LM_ERR ERR
On Mar 02, 2009 at 17:26, Jan Janak jan@iptel.org wrote:
Module: sip-router Branch: master Commit: f5618c1a54e9190bda9057f07caf700d0c96ca65 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f5618c1a...
Author: Jan Janak jan@iptel.org Committer: Jan Janak jan@iptel.org Date: Mon Mar 2 17:23:17 2009 +0100
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.
There are a few more minor LOG() changes that I think we should do. I've just spoken about some other LOG() changes with Ondrej.
I think we need a LOG function similar to LOG_() but for which both the log level name and the location prefix can be changed. Something like:
LOG_raw(level, prefix1, prefix2, fmt, args...)
and then:
LOG(level, fmt, args...) = LOG_raw(level, LOG_LEVEL2NAME(level), LOC_INFO, fmt, args...)
LOG_(level, prefix, fmt, args...) = LOG_raw(level, LOG_LEVEL2NAME(level), prefix, fmt, args...)
LOG_noloc(level, fmt, args...) = LOG_raw(level, LOG_LEVEL2NAME(level), "", fmt, args...)
LOG_nolev(level, fmt, args...) = LOG_raw(level, "", LOC_INFO, fmt, args ...)
LOG_pure(level, fmt, args...) = LOG_raw(level, "", "", fmt, args...)
(the names should be shorter, I used longer versions just to make this example more readable).
We need some of them in some parts of the current code (e.g. we don't want log level names added for the script log or for the memory/malloc logs) and we'll also be future proof.
We also need a L_BUG different from L_CRIT (Ondrej code would add a BUG prefix to all the L_CRIT messages and many of them are just critical errors and not bugs).
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
Andrei
On 02-03 17:48, Andrei Pelinescu-Onciul wrote:
On Mar 02, 2009 at 17:26, Jan Janak jan@iptel.org wrote:
Module: sip-router Branch: master Commit: f5618c1a54e9190bda9057f07caf700d0c96ca65 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f5618c1a...
Author: Jan Janak jan@iptel.org Committer: Jan Janak jan@iptel.org Date: Mon Mar 2 17:23:17 2009 +0100
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.
There are a few more minor LOG() changes that I think we should do. I've just spoken about some other LOG() changes with Ondrej.
I think we need a LOG function similar to LOG_() but for which both the log level name and the location prefix can be changed. Something like:
LOG_raw(level, prefix1, prefix2, fmt, args...)
and then:
LOG(level, fmt, args...) = LOG_raw(level, LOG_LEVEL2NAME(level), LOC_INFO, fmt, args...)
LOG_(level, prefix, fmt, args...) = LOG_raw(level, LOG_LEVEL2NAME(level), prefix, fmt, args...)
LOG_noloc(level, fmt, args...) = LOG_raw(level, LOG_LEVEL2NAME(level), "", fmt, args...)
LOG_nolev(level, fmt, args...) = LOG_raw(level, "", LOC_INFO, fmt, args ...)
LOG_pure(level, fmt, args...) = LOG_raw(level, "", "", fmt, args...)
(the names should be shorter, I used longer versions just to make this example more readable).
We need some of them in some parts of the current code (e.g. we don't want log level names added for the script log or for the memory/malloc logs) and we'll also be future proof.
We also need a L_BUG different from L_CRIT (Ondrej code would add a BUG prefix to all the L_CRIT messages and many of them are just critical errors and not bugs).
Sure, feel free to do the changes, I should be fine as long as we have a macro which also takes the logging facility as a parameter. There is currently only one module which uses it (kamailio acc), but I think this is good to have and I'd like to preserve it after the merger.
Jan.