ngocnhan-tran1996 opened a new issue, #2666:
URL: https://github.com/apache/logging-log4j2/issues/2666

   I have an application use log4j2 template layout with below config
   
   File `EcsLayout.json`
   ```json
   {
     "message1": {
       "$resolver": "pattern",
       "pattern": "${env:TZ:-%d{yyyy-MM-dd HH:mm:ss.SSS}{UTC+07}}"
     },
     "message2": {
       "$resolver": "pattern",
       "pattern": "${env:TZ:-${TIMEZONE}}"
     }
   }
   ```
   
   File `log4j2.xml`
   
   ```xml
   <?xml version="1.0" encoding="UTF-8"?>
   <Configuration name="Mask Library Test" 
xmlns:xi="http://www.w3.org/2001/XInclude";>
   
     <Properties>
       <Property name="TIMEZONE">%d{yyyy-MM-dd HH:mm:ss.SSS}{UTC+07}</Property>
     </Properties>
   
     <Appenders>
       <Console name="Console" target="SYSTEM_OUT">
         <PatternLayout
           disableAnsi="false"
           pattern="%style{${TIMEZONE}}{black} 
%highlight{%-5level}[%style{%t}{bright,blue}] %style{%c{1.}}{bright,yellow}: 
%m%n%throwable" />
       </Console>
   
       <RollingFile name="RollingFile"
         filePattern="logs/app-%d{yyyy-MM-dd-HH-mm}.log">
         <JsonTemplateLayout eventTemplateUri="classpath:EcsLayout.json" />
   
         <TimeBasedTriggeringPolicy />
       </RollingFile>
     </Appenders>
   
     <Loggers>
       <Root level="info">
         <AppenderRef ref="Console" />
         <AppenderRef ref="RollingFile" />
       </Root>
     </Loggers>
   </Configuration>
   ```
   
   And file log
   
   ```text
   {"message1":"${env:TZ:-2024-06-14 15:00:33.561}","message2":"%d{yyyy-MM-dd 
HH:mm:ss.SSS}{UTC+07}"}
   ```
   
   **Expected**
   
   **message1**
   If `env:TZ` do not exist, it will be replace by `{yyyy-MM-dd 
HH:mm:ss.SSS}{UTC+07}`
   
   or
   
   **message2**
   log will be recorded date time instead `"%d{yyyy-MM-dd 
HH:mm:ss.SSS}{UTC+07}"`
   
   
   I have a small demo, just run and go to file 
`logs/app-{yyyy-MM-dd-HH-mm}.log` and you will see result. Please tell me if I 
miss something.
   
   https://github.com/ngocnhan-tran1996/log4j2-demo


-- 
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