ppkarwasz commented on issue #4001:
URL: 
https://github.com/apache/logging-log4j2/issues/4001#issuecomment-3951006227

   Hi @snicoll,
   
   Sorry for the delay: busy times at my day job.
   
   The issue appears to be caused by the `filePattern` used in 
spring-projects/spring-boot#47260:
   
   ```xml
   <RollingFile name="File" fileName="${sys:LOG_FILE}"
                
filePattern="${sys:LOG4J2_ROLLINGPOLICY_FILE_NAME_PATTERN:-${sys:LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}">
   ```
   
   After substitution, this effectively becomes:
   
   ```
   myapp.log.%d{yyyy-MM-dd.%i.gz}
   ```
   
   This string matches the regex used to detect `%i` 
(`.*%(?<ZEROPAD>0)?(?<PADDING>\d+)?i.*`), but it does **not** actually contain 
a real `%i` rollover token: the `%i` is inside the date format. That mismatch 
triggers the failure described in this issue.
   
   ### Expansion logic
   
   This happens because `StrSubstitutor` does not support escaping `}` (see 
apache/logging-log4j2#2679). Although it supports nested `${...}` expressions, 
it treats the `}` in `%d{yyyy-MM-dd}` as the closing brace of the outer 
substitution.
   
   As a result, the default value is prematurely terminated and effectively 
parsed as:
   
   ```
   ${sys:LOG_FILE}.%d{yyyy-MM-dd
   ```
   
   which expands to:
   
   ```
   myapp.log.%d{yyyy-MM-dd
   ```
   
   The remaining `.%i.gz}` is then treated as a **literal** suffix and appended 
unchanged.
   
   ### Workaround
   
   Instead of using the `:-` default syntax, define the default via a dedicated 
property:
   
   ```xml
   <Properties>
     <Property name="LOG4J2_ROLLINGPOLICY_FILE_NAME_PATTERN"
               value="${sys:LOG_FILE}.%d{yyyy-MM-dd}.%i.gz"/>
   </Properties>
   
   <Appenders>
     <RollingFile name="File"
                  fileName="${sys:LOG_FILE}"
                  filePattern="${sys:LOG4J2_ROLLINGPOLICY_FILE_NAME_PATTERN}">
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to