logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Cheryl_Mrozien...@Dell.com>
Subject defer creation of RollingFileAppender log files when Logger and/or AppenderRef level attribute has a value of "OFF"?
Date Thu, 07 Jul 2016 19:26:15 GMT
Dell - Internal Use - Confidential
 Hi,

I am currently using Log4j version 2.3, but might be able to update to a newer version if
that would help.

I have a log4j2.xml file containing more than thirty RollingFileAppenders (one per product
component).  Most of these RollingFileAppenders will not be written to until the user turns
on logging via our product's user interface.  By default, the AppenderRefs that reference
these RollingFileAppenders have the "level" attribute set to a value of "OFF".  Once the user
turns on logging from the user interface, the "level" attribute will be updated with a value
of "INFO", "DEBUG", etc.  And, once the updated log4j2.xml file is persisted, the code will
then call LoggerContext.reconfigure() to get Log4j to read in the new log4j2.xml file, so
the new log levels take effect.

My question is whether there is a way to tell Log4j to defer log file creation when nothing
will initially write to the file (e.g. all references to the Appender have a level of "OFF")?
 Having lots of zero sized log files is not that big of an issue, although not completely
optimal.  However, having too many open file handles that are not doing anything, could potentially
become an issue.  Note that I do not have control over the number of Appenders configured
for the product.  Each product component team contributes its Appender and Loggers to log4j2.xml.

To work around the open file handle issue at server startup time, I am currently using the
Log4j2 private core API calls to loop through the AppenderRefs to determine which ones are
"OFF", and then I'm calling the RollingFileAppender.stop() method to close the output stream.
 If anyone has any ideas that would avoid creating and opening the log files in the first
place, I'd love to hear your thoughts.

Thanks and regards,

-Cheryl

p.s. for reference, the relevant log4j2.xml snippets follow:

<Appenders>
    <RollingFile
      fileName="${sys:com.compellent.msaserviceDir}/etc/compservices/debuglogs/Scheduler/Scheduler.debuglog"
      filePattern="${sys:com.compellent.msaserviceDir}/etc/compservices/debuglogs/Scheduler/Scheduler_%i.debuglog.gz"
      name="debug.Scheduler">
      <PatternLayout>
        <Pattern>%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p {%C:%M} [%marker] (%t) - %msg%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="50 MB"/>
      </Policies>
      <DefaultRolloverStrategy max="10"/>
      <Filters>
        <MarkerFilter marker="Scheduler" onMatch="ACCEPT" onMismatch="DENY"/>
      </Filters>
    </RollingFile>
</Appenders>

<Loggers>
    <Logger includeLocation="true" level="TRACE" name="debugLogger">
      <AppenderRef level="DEBUG" ref="debug.ModuleManager"/>
      <AppenderRef level="OFF" ref="debug.Scheduler"/>
    </Logger>
</Loggers>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message