0

There is a class Task. Inherited from Thread.

How do I configure the log4j2 logger to create and write Task-1.log for each thread Task?

My xml:

    <?xml version="1.0" encoding="UTF-8"?>
<Properties>
    <Property name="pattern">%d{yyyy-MM-dd HH:mm:ss.SSS} [%level] [thread-id %T] %l - %msg%n</Property>
</Properties>

<Appenders>
    <RollingFile name="fileLogger" fileName="${sys:logFolder}/test.log" filePattern="${sys:logFolder}/test-%d{yyyy-MM-dd}.log">
        <PatternLayout>
            <pattern>${pattern}</pattern>
        </PatternLayout>
        <Policies>
            <TimeBasedTriggeringPolicy interval="1" modulate="true" />
        </Policies>
    </RollingFile>

    <Console name="console" target="SYSTEM_OUT">
        <PatternLayout pattern="${pattern}" />
    </Console>

</Appenders>

<Loggers>
    <Root level="info" additivity="false">
        <appender-ref ref="console" />
        <appender-ref ref="fileLogger" />
    </Root>
    <Logger name="com.test.*" level="info">
        <appender-ref ref="fileLogger" level="info" />
    </Logger>
</Loggers>
Tsyklop
  • 369
  • 1
  • 9
  • 24
  • see https://stackoverflow.com/questions/2763740/log4j-log-output-of-a-specific-class-to-a-specific-appender, I think your question is a duplicate. – geco17 Dec 12 '17 at 20:22
  • @WilliamBurnham it for log4j, but i use log4j2 – Tsyklop Dec 12 '17 at 20:23
  • Sorry, I misread. Just the same, I think your question has been asked before. https://stackoverflow.com/questions/19976211/different-log-files-for-multiple-threads-using-log4j2 – geco17 Dec 12 '17 at 20:27
  • @WilliamBurnham not working. i get error: `No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender` – Tsyklop Dec 12 '17 at 20:50
  • What version of log4j2 are you using? https://stackoverflow.com/questions/14657572/getting-error-trying-to-create-log4j2-rollingfileappender may help – geco17 Dec 12 '17 at 20:57
  • @WilliamBurnham 2.10. I have no error in the config - `The error was in the fillet of the Parameter - it has the same value in both applications.` – Tsyklop Dec 12 '17 at 21:08
  • @Tsyklop this is the same question from you right? https://stackoverflow.com/questions/47761294/configuring-log4j2-for-threads I asked a question in comments – Sudheera Dec 13 '17 at 06:53

0 Answers0