[
https://issues.apache.org/jira/browse/LOG4J2-649?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Remko Popma updated LOG4J2-649:
-------------------------------
Description:
I'm using the Routing functionality in Log4j 2 to dynamically create appenders
at runtime. When I know that those appenders are finished with, I'd like to
tell Log4j so that it can tidy up the related resources (flush & close files,
free its internal objects related to those appenders, etc.). Without doing
this, Log4j still has open file handles and I'm unable to manipulate the files
that it has written (from an external process which post-processes and archives
the logs).
Remko Popma tells me (via the stackoverflow answer at
http://stackoverflow.com/a/23827382/799399) that there is no way of doing this
at the moment. I'd like to request that you consider enhancing Log4j 2 in this
way.
I enclose my configuration below, in case it's relevant (but I think all the
details you need are included in the above description).
{code}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %level{ERROR=!, WARN=?, INFO=-,
DEBUG=., TRACE=.} %msg%n"/>
</Console>
<Routing name="MatchLogs">
<Routes pattern="$${ctx:matchID}">
<Route>
<RandomAccessFile name="MatchLog-${ctx:matchID}"
fileName="logs/${ctx:matchID}.log">
<PatternLayout pattern="%d{ISO8601} %-5level %-30.30logger{1}
%msg%n"/>
</RandomAccessFile>
</Route>
</Routes>
</Routing>
<Async name="AsyncWrapper">
<AppenderRef ref="MatchLogs" level="debug"/>
<AppenderRef ref="Console" level = "info"/>
</Async>
<Routing name="MatchStatsLogs">
<Routes pattern="$${ctx:matchID}">
<Route>
<RandomAccessFile name="MatchStatsLog-${ctx:matchID}"
fileName="logs/${ctx:matchID}_stats.log">
<PatternLayout pattern="%msg"/>
</RandomAccessFile>
</Route>
</Routes>
</Routing>
<Async name="AsyncStatsWrapper">
<AppenderRef ref="MatchStatsLogs" level="debug"/>
</Async>
</Appenders>
<Loggers>
<Logger name="stats" level="trace" additivity="false">
<AppenderRef ref="AsyncStatsWrapper"/>
</Logger>
<Root level="debug">
<AppenderRef ref="AsyncWrapper"/>
</Root>
</Loggers>
</Configuration>
{code}
was:
I'm using the Routing functionality in Log4j 2 to dynamically create appenders
at runtime. When I know that those appenders are finished with, I'd like to
tell Log4j so that it can tidy up the related resources (flush & close files,
free its internal objects related to those appenders, etc.). Without doing
this, Log4j still has open file handles and I'm unable to manipulate the files
that it has written (from an external process which post-processes and archives
the logs).
Remko Popma tells me (via the stackoverflow answer at
http://stackoverflow.com/a/23827382/799399) that there is no way of doing this
at the moment. I'd like to request that you consider enhancing Log4j 2 in this
way.
I enclose my configuration below, in case it's relevant (but I think all the
details you need are included in the above description).
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %level{ERROR=!, WARN=?, INFO=-,
DEBUG=., TRACE=.} %msg%n"/>
</Console>
<Routing name="MatchLogs">
<Routes pattern="$${ctx:matchID}">
<Route>
<RandomAccessFile name="MatchLog-${ctx:matchID}"
fileName="logs/${ctx:matchID}.log">
<PatternLayout pattern="%d{ISO8601} %-5level %-30.30logger{1}
%msg%n"/>
</RandomAccessFile>
</Route>
</Routes>
</Routing>
<Async name="AsyncWrapper">
<AppenderRef ref="MatchLogs" level="debug"/>
<AppenderRef ref="Console" level = "info"/>
</Async>
<Routing name="MatchStatsLogs">
<Routes pattern="$${ctx:matchID}">
<Route>
<RandomAccessFile name="MatchStatsLog-${ctx:matchID}"
fileName="logs/${ctx:matchID}_stats.log">
<PatternLayout pattern="%msg"/>
</RandomAccessFile>
</Route>
</Routes>
</Routing>
<Async name="AsyncStatsWrapper">
<AppenderRef ref="MatchStatsLogs" level="debug"/>
</Async>
</Appenders>
<Loggers>
<Logger name="stats" level="trace" additivity="false">
<AppenderRef ref="AsyncStatsWrapper"/>
</Logger>
<Root level="debug">
<AppenderRef ref="AsyncWrapper"/>
</Root>
</Loggers>
</Configuration>
If the goal of your request is to manipulate these log files from an external
process, you might be able to do that by using a FileAppender instead of a
RandomAccessFileAppender.
> Close a dynamically created appender
> ------------------------------------
>
> Key: LOG4J2-649
> URL: https://issues.apache.org/jira/browse/LOG4J2-649
> Project: Log4j 2
> Issue Type: Improvement
> Components: API, Appenders
> Affects Versions: 2.0-rc1
> Environment: Windows 7 (64-bit)
> Reporter: Andrew Rose
>
> I'm using the Routing functionality in Log4j 2 to dynamically create
> appenders at runtime. When I know that those appenders are finished with, I'd
> like to tell Log4j so that it can tidy up the related resources (flush &
> close files, free its internal objects related to those appenders, etc.).
> Without doing this, Log4j still has open file handles and I'm unable to
> manipulate the files that it has written (from an external process which
> post-processes and archives the logs).
> Remko Popma tells me (via the stackoverflow answer at
> http://stackoverflow.com/a/23827382/799399) that there is no way of doing
> this at the moment. I'd like to request that you consider enhancing Log4j 2
> in this way.
> I enclose my configuration below, in case it's relevant (but I think all the
> details you need are included in the above description).
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="WARN">
> <Appenders>
> <Console name="Console" target="SYSTEM_OUT">
> <PatternLayout pattern="%d{HH:mm:ss.SSS} %level{ERROR=!, WARN=?,
> INFO=-, DEBUG=., TRACE=.} %msg%n"/>
> </Console>
> <Routing name="MatchLogs">
> <Routes pattern="$${ctx:matchID}">
> <Route>
> <RandomAccessFile name="MatchLog-${ctx:matchID}"
> fileName="logs/${ctx:matchID}.log">
> <PatternLayout pattern="%d{ISO8601} %-5level %-30.30logger{1}
> %msg%n"/>
> </RandomAccessFile>
> </Route>
> </Routes>
> </Routing>
> <Async name="AsyncWrapper">
> <AppenderRef ref="MatchLogs" level="debug"/>
> <AppenderRef ref="Console" level = "info"/>
> </Async>
> <Routing name="MatchStatsLogs">
> <Routes pattern="$${ctx:matchID}">
> <Route>
> <RandomAccessFile name="MatchStatsLog-${ctx:matchID}"
> fileName="logs/${ctx:matchID}_stats.log">
> <PatternLayout pattern="%msg"/>
> </RandomAccessFile>
> </Route>
> </Routes>
> </Routing>
> <Async name="AsyncStatsWrapper">
> <AppenderRef ref="MatchStatsLogs" level="debug"/>
> </Async>
> </Appenders>
> <Loggers>
> <Logger name="stats" level="trace" additivity="false">
> <AppenderRef ref="AsyncStatsWrapper"/>
> </Logger>
> <Root level="debug">
> <AppenderRef ref="AsyncWrapper"/>
> </Root>
> </Loggers>
> </Configuration>
> {code}
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]