[Log4cplus-devel] [log4cplus:bugs] #342 fShadowEnvironment does not allow for optional variables (w
Logging Framework for C++
Brought to you by:
wilx
|
From: Václav H. <wi...@us...> - 2017-06-21 10:46:23
|
- **labels**: --> properties
- Description has changed:
Diff:
~~~~
--- old
+++ new
@@ -1,31 +1,38 @@
-Unfortunately fShadowEnvironment doesn't go nice together with fAllowEmptyVars.
+Unfortunately `fShadowEnvironment` doesn't go nice together with `fAllowEmptyVars`.
Here is the case. My config file contains the line:
+
+```properties
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
+
+- `${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).
+1. use `fShadowEnvironment`
-c) fShadowEnvironment | fAllowEmptyVars
-Which also doesn't work. As it will never read system variables.
+ 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`
-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.
+2. `fAllowEmptyVars`
+ It will try to read every thing from System (will skip all custom variables).
+3. `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.
+
+```cpp
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 ()))
@@ -48,4 +55,4 @@
// Nothing has been subtituted, just move beyond the
// unexpanded variable.
i = var_end + DELIM_STOP_LEN;
-~~~
+```
~~~~
- **assigned_to**: Václav Haisman
---
** [bugs:#342] fShadowEnvironment does not allow for optional variables (which can be empty)**
**Status:** open
**Group:** v1.1.3
**Labels:** properties
**Created:** Tue Jun 20, 2017 06:57 PM UTC by Jan Vogelgesang
**Last Updated:** Wed Jun 21, 2017 10:22 AM UTC
**Owner:** Václav Haisman
Unfortunately `fShadowEnvironment` doesn't go nice together with `fAllowEmptyVars`.
Here is the case. My config file contains the line:
```properties
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:
1. 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`
2. `fAllowEmptyVars`
It will try to read every thing from System (will skip all custom variables).
3. `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.
```cpp
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. |