[Log4cplus-devel] [log4cplus:bugs] #342 fShadowEnvironment does not allow for optional variables (w
Logging Framework for C++
Brought to you by:
wilx
From: Jan V. <jan...@us...> - 2017-06-21 10:22:44
|
I think the code should be changed to something like: bool propertyExist = props.exists(key); if (propertyExist) { replacement = props.getProperty(key); } // if shadowing is not allowed or a property was not registered then try to look up in envrionment variables if (!shadow_env || !propertyExist) { internal::get_env_var(replacement, key); } // if empty values allowed or value is not empty then perform remplacement if (empty_vars || !replacement.empty ()) { .... --- ** [bugs:#342] fShadowEnvironment does not allow for optional variables (which can be empty)** **Status:** open **Group:** v1.1.3 **Created:** Tue Jun 20, 2017 06:57 PM UTC by Jan Vogelgesang **Last Updated:** Tue Jun 20, 2017 07:06 PM UTC **Owner:** nobody Unfortunately fShadowEnvironment doesn't go nice together with fAllowEmptyVars. Here is the case. My config file contains the line: appender.applog.File=${ProgramData}\${logname}-${USERNAME}${optionalSuffix}.log So I have both Environment Variables and my custom variables which I set in the code. ${OptionalSuffix} is added only if app is run from command line, otherwise I would like to have it empy. ${UserName} I set manually in the code only when app is run as a services. ${logname} is my log name set in the code ${ProgramData} is an environment variable I don't touch in the code I have 3 options: a) use fShadowEnvironment Then I will have correctly resolved all variables but when ${optionalSuffix} is empty then I will end up with the log name: C:\ProgramData\MyLogName-janekvogel${optionalSuffix}.log b) fAllowEmptyVars: It will try to read every thing from System (will skip all custom variables). c) fShadowEnvironment | fAllowEmptyVars Which also doesn't work. As it will never read system variables. I think the best approach would be just to remove the not resolved property. So in fShadowEnvironment ${optionalSuffix} should be replaced with empty string if optionalSuffix is not found neither in properties nor in system variables. else // Nothing has been subtituted, just move beyond the // unexpanded variable. // TODO: replace unresolved property with empty string i = var_end + DELIM_STOP_LEN; ~~~ if (shadow_env) replacement = props.getProperty (key); if (! shadow_env || (! empty_vars && replacement.empty ())) internal::get_env_var (replacement, key); if (empty_vars || ! replacement.empty ()) { // Substitute the variable with its value in place. pattern.replace (var_start, var_end - var_start + DELIM_STOP_LEN, replacement); changed = true; if (rec_exp) // Retry expansion on the same spot. continue; else // Move beyond the just substituted part. i = var_start + replacement.size (); } else // Nothing has been subtituted, just move beyond the // unexpanded variable. i = var_end + DELIM_STOP_LEN; ~~~ --- Sent from sourceforge.net because log...@li... is subscribed to https://sourceforge.net/p/log4cplus/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/log4cplus/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |