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 codeI have 3 options:
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
fAllowEmptyVars
It will try to read every thing from System (will skip all custom variables).
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 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;
I think the code should be changed to something like:
Last edit: Václav Haisman 2017-06-21
Diff: