Hi, Objective: Dump a "history" of recent program operations to a log file when an Exception arises. By logging to a CyclicBufferAppender, a recent history at a fairly granular level (INFO, or possibly DEBUG) can be maintained without accumulating massive amounts of data, and with a minimum of overhead.
Setting this up to log to the Cyclical Buffer went well. To get the data out of the CyclicBuffer and log it to a file, a reference to the CyclicBufferAppender object is needed, and it is not clear how to get one. It seems like log.getAppender(String name) should return an Appender, but it doesn't. How can I obtain such a reference? Also, once a reference is obtained, and an Object is returned from cyclicBufferAppender.get(i), what class will that object be? I'm hoping it is a LoggingEvent object, in which case a simple call to the fileAppender.doAppend method with the event as a parameter will log the event to a "permanent" log. Again, the code will need to obtain a reference to the appropriate FileAppender to log it to. (Appropriate might be hardcoded, or specified in a properties file.) Most of the configuration is being done in logback.xml. (File is attached.) Program code, other than wanting to dump the MEMORY appender, is limited to: static final Logger log = LoggerFactory.getLogger(Main.class); and various log.X method calls. As an aside, it would be even better to loop over all Appenders, and check to see which ones are CyclicBufferAppenders. The code would dump then contents of all of the CyclicBufferAppenders, or selected ones based on some user options. Thanks in advance for your insight. Mike
<!-- logback.xml Parameters Client (default: mun) Used to assign name of log file FileLevel (default: WARN) Limit messages logged to the log file ConsoleLevel (default: ERROR) Limit messages logged to the console MemoryLevel (default: INFO) Limit messages logged to memory (and written to the log file upon an exception) --> <configuration debug="true"> <!-- <substitutionProperty file="iDC.properties" /> --> <substitutionProperty name="Client" value="mun" /> <substitutionProperty name="FileLevel" value="WARN" /> <substitutionProperty name="ConsoleLevel" value="ERROR" /> <substitutionProperty name="MemoryLevel" value="INFO" /> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern> </layout> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>${FileLevel}</level> </filter> <File>/logs/${Client}/WebServices.log</File> <Append>true</Append> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>1MB</MaxFileSize> </triggeringPolicy> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <FileNamePattern>WebServices.%i.log</FileNamePattern> <MinIndex>1</MinIndex> <MaxIndex>9</MaxIndex> </rollingPolicy> </appender> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern> </layout> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>${ConsoleLevel}</level> </filter> </appender> <appender name="MEMORY" class="ch.qos.logback.core.read.CyclicBufferAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern> </layout> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>${MemoryLevel}</level> </filter> <MaxSize>1000</MaxSize> </appender> <root> <level value="debug" /> <appender-ref ref="FILE" /> <appender-ref ref="STDOUT" /> <appender-ref ref="MEMORY" /> </root> </configuration>
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user