Hello Gary, Yes, the log file is deleted externally. In my case, it is deleted by a cron job.
Surprisingly, I don't see any internal log4j2 errors when the file is deleted and the new log events are not logged into the same file anymore. And yes, we are talking about deleting the same file which was created by appender. Should the file be locked by the Appender while it is writing logs? Also, why does the appender not create a new log file, when old log file is deleted externally? Thanks for looking into this. Regards, Anhad On Thu, Aug 31, 2017 at 8:52 PM, Gary Gregory <garydgreg...@gmail.com> wrote: > Hello Anhad, > > Are you saying that the log file is deleted externally to the JVM writing > it? For example, a user or another program deletes the log file? > > Do you see any errors on the console that might be logged by the internal > Log4j status logger? > > Also, are we talking about the active file managed by the file appender? I > am surprised that the file is not locked. > > Gary > > On Thu, Aug 31, 2017 at 1:03 PM, Anhad Singh Bhasin <anhadbha...@gmail.com > > > wrote: > > > 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> > > >