[ 
https://issues.apache.org/jira/browse/LOG4J2-3433?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17505895#comment-17505895
 ] 

Ralph Goers commented on LOG4J2-3433:
-------------------------------------

It would have been helpful to see the log4j 1.x configuration that you say 
worked. Based on what you asked for here is the XML configuration (I don't like 
working with the properties configuration).

 
{code:java}
<Configuration status="WARN" name="SampleConfig">
  <Appenders>
    <Console name="LogToConsole">
      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} (%t) %-5level 
[%logger\{36}.%M:%L] - %msg%n"/>
    </Console>
    <RollingFile name="pack1 fileName="logs/pack1.log" 
filePattern="logs/$${date:yyyy-MM}/pack1-%d{MM-dd-yyyy}-%i.log.gz">
      <PatternLayout>
        <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} (%t) %-5level [%logger\{36}.%M:%L] 
- %msg%n</Pattern>
      </PatternLayout>
      <DefaultRolloverStrategy max="10"/>
      <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
      <SizeBasedTriggeringPolicy size="10MB"/>
    </RollingFile>
    <RollingFile name="pack2" fileName="logs/pack2.log" 
filePattern="logs/$${date:yyyy-MM}/pack2-%d{MM-dd-yyyy}-%i.log.gz">
      <PatternLayout>
        <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} (%t) %-5level [%logger\{36}.%M:%L] 
- %msg%n</Pattern>
      </PatternLayout>
      <DefaultRolloverStrategy max="10"/>
      <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
      <SizeBasedTriggeringPolicy size="10MB"/>
    </RollingFile>
  </Appenders>

  <Loggers>
    <Logger name="com.application.test.pack1" level="debug" additivity="false">
      <AppenderRef ref="pack1"/>
      <AppenderRef ref="LogToConsole"/>
    </Logger>
    <Logger name="com.application.test.pack2" level="debug" additivity="false">
      <AppenderRef ref="pack2/>
      <AppenderRef ref="LogToConsole"/>
     </Logger>
    <Root level="INFO">
      <AppenderRef ref="LogToConsole"/>
    </Root>
  </Loggers>

</Configuration> {code}
Note that with this configuration the second appenderRef could be removed and 
additivity set to true.
Also, no Delete action is configured so the disk will eventually fill up.

 

 

 

 

> Multiple log files need to be generated based on package
> --------------------------------------------------------
>
>                 Key: LOG4J2-3433
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3433
>             Project: Log4j 2
>          Issue Type: Request
>          Components: Appenders, Configuration
>    Affects Versions: 2.17.2
>         Environment: linux OS
>            Reporter: Thangadurai Kandhasamy
>            Priority: Blocker
>              Labels: documentation, features
>         Attachments: log4j2.properties
>
>
> Team,
> We are using Apache log4j 1.2.x we are able to generate Multiple log files 
> based on package.
> As we planned to upgrade from 1.2.x to 2.17.0 we are not able to generate 
> Multiple log files based on package.
> Assume our packages are
> 1.com.application.test.pack1
> 2.com.application.test.pack2
> As per below configuration {+}we could get all the logs into *single log 
> file*{+}.
>     logger.app.name = com.application.test
> We +expect to log all the logs related+ to *com.application.test.pack1* 
> should be *{color:#ff8b00}pack1.log{color};*   same way 
> *com.application.test.pack2* should be *{color:#ff8b00}pack2.log{color},* We 
> tried multiple options and also referred official documentation site 
> [https://logging.apache.org/log4j/2.x/manual/appenders.html]. However we 
> don't find any reference based on our need. 
> Below is the log4j2.properties. Same you can find in the attachment section.
> _______________________________________________________
> status = warn
> appender.console.type = Console
> appender.console.name = LogToConsole
> appender.console.layout.type = PatternLayout
> appender.console.layout.pattern =  %d\{yyyy-MM-dd HH:mm:ss.SSS} (%t) %-5level 
> [%logger\{36}.%M:%L] - %msg%n
> # Rotate log file
> appender.rolling.type = RollingFile
> appender.rolling.name = LogToRollingFile
> appender.rolling.fileName = logs/{*}{color:#ff8b00}app.log{color}{*}
> appender.rolling.filePattern = 
> logs/$${date:yyyy-MM}/app-%d\{MM-dd-yyyy}-%i.log.gz
> appender.rolling.layout.type = PatternLayout
> appender.rolling.layout.pattern = %d\{yyyy-MM-dd HH:mm:ss.SSS} (%t) %-5level 
> [%logger\{36}.%M:%L] - %msg%n
> appender.rolling.policies.type = Policies
> appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
> appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
> appender.rolling.policies.size.size=10MB
> appender.rolling.strategy.type = DefaultRolloverStrategy
> appender.rolling.strategy.max = 10
> # Log to console and rolling file
> logger.app.name = *com.application.test*
> logger.app.level = debug
> logger.app.additivity = false
> logger.app.appenderRef.rolling.ref = LogToRollingFile
> logger.app.appenderRef.console.ref = LogToConsole
> rootLogger.level = info
> rootLogger.appenderRef.stdout.ref = LogToConsole
> _______________________________________________________
>  
> Please advise.
>  
> Regards
> Thanga



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to