Hello All,

Great to see Log4j 2.9.0 release. Thanks to all the contributors.

I have TCPSocketServer running on Edge node of a cluster and all other data
nodes send log events to the TCPSocketServer running on edge node. And I am
using standard routing to redirect log events to individual log files.

<Route>
      <RollingFile name="WorkerFile" fileName="/opt//logs/${ctx:logId}.log"
filePattern="/opt/logs/${ctx:logId}-%i.log">
        <PatternLayout>
          <pattern>%d{ISO8601} [%t] %p %c{3} - %m%n</pattern>
        </PatternLayout>
        <Policies>
          <SizeBasedTriggeringPolicy size="100 MB" />
        </Policies>
      </RollingFile>
</Route>

** Full configurations are below **

The Routing creates a new log file for each of the context first time the
log event for that context is sent and log events received by the server
are recorded into their appropriate log files. The problem occurs when one
of the log file is deleted. If one of the log file is deleted, the new log
events corresponding to that context are lost and no new file gets created.
The work around is to restart the TCPSocketServer. After the restart, a new
log file gets created again and then all the log events gets recorded
appropriately. I am trying to find out if there is a way the log events
create a new file if the old log file is deleted somehow.

Any suggestions, comments would be deeply appreciated.

Thanks for your time.
Regards,
Anhad Singh Bhasin



*log4j2.xml *

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="TRACE" name="XLogging" monitorInterval="30">
  <Appenders>
    <Socket name="XSocket" host="X" port="5235" >
      <SerializedLayout />
    </Socket>
    <Async name="AsyncFile">
      <AppenderRef ref="XSocket"/>
    </Async>
    </Appenders>
  <Loggers>
    <Root level="WARN">
      <AppenderRef ref="AsyncFile"/>
    </Root>
    <AsyncLogger name="org.reflections.Reflections" level="ERROR" />
    <AsyncLogger name="org.apache.hadoop" level="INFO" />
    <AsyncLogger name="com.X" level="DEBUG" />
  </Loggers>
</Configuration>


*log4j2-server.xml *
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="TRACE" name="XLogging" monitorInterval="30">
  <Appenders>
    <Routing name="Routing">
    <Routes pattern="$${ctx:logId}">
<Route>
      <RollingFile name="XWorkerFile" fileName="/opt/logs/${ctx:logId}.log"
filePattern="/opt/logs/${ctx:logId}-%i.log">
        <PatternLayout>
          <pattern>%d{ISO8601} [%t] %p %c{3} - %m%n</pattern>
        </PatternLayout>
        <Policies>
          <SizeBasedTriggeringPolicy size="1 MB" />
        </Policies>
      </RollingFile>
    </Route>
</Routes>
    </Routing>
    <Async name="AsyncFile">
        <AppenderRef ref="Routing" />
    </Async>
  </Appenders>
  <Loggers>
    <Root level="WARN">
      <AppenderRef ref="AsyncFile"/>
    </Root>
    <AsyncLogger name="org.reflections.Reflections" level="ERROR" />
    <AsyncLogger name="org.apache.hadoop" level="INFO" />
    <AsyncLogger name="com.X" level="DEBUG" />
  </Loggers>
</Configuration>

Reply via email to