Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-3433

Multiple log files need to be generated based on package

    XMLWordPrintableJSON

Details

    • Request
    • Status: Resolved
    • Blocker
    • Resolution: Information Provided
    • 2.17.2
    • None
    • Appenders, Configuration
    • linux OS

    Description

      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 pack1.log;   same way com.application.test.pack2 should be pack2.log, 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

      1. Rotate log file
        appender.rolling.type = RollingFile
        appender.rolling.name = LogToRollingFile
        appender.rolling.fileName = logs/app.log
        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
      1. 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

      Attachments

        1. log4j2.properties
          1 kB
          Thangadurai Kandhasamy

        Activity

          People

            Unassigned Unassigned
            thangadurai Thangadurai Kandhasamy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: