Skip to content

exacode/logback-extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Extensions for logback - Java logger

RecordingAppender

This recording appender comes from great blog post Tomasz Nurkiewicz - MongoDB and recording appenders for Logback. It allows you to minimize log count by dumping only really important parts.

Configuration consists of:

  • target appender that will receive log dump
  • log level that triggers log dump
  • number of logs that will be kept in the memory (buffer) unless they are dumpped or removed
  • when logs kept in the buffer should be removed (without dump)

See full RecordingAppender Configuration.

Example configuration - logback.xml

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
	<encoder>
		<pattern>%-4relative [%thread] %-5level - %msg%n</pattern>
	</encoder>
</appender>

<appender name="REC" class="net.exacode.logback.classic.recording.RecordingAppender">
	<appender-ref ref="STDOUT" />

	<maxEvents>10</maxEvents>
	<dumpThreshold>ERROR</dumpThreshold>
	<expiryTimeMs>100</expiryTimeMs>
</appender>

<root level="DEBUG">
	<appender-ref ref="REC" />
</root>

MongoDbAppender

MongoDbAppender allows you to dump logs to MongoDB collection. By default this appender uses capped collections (that works like circular buffer). Moreover this jar provides also a MongoDbLogDao that is an easy way of retrieving logs from MongoDB.

See full MongoDbAppender Configuration.

MongoDbAppender is again a simple modification of an idea and code available on great (really!) blog post Tomasz Nurkiewicz - MongoDB and recording appenders for Logback. My changes:

  • Changed deprecated API invocations
  • Added marshaller and unmarshaller of ILoggingEvents
  • Added support for capped collections
  • Modified tests (parameterized mongo server address, etc...)

Example configuration - logback.xml

	<?xml version="1.0" encoding="UTF-8" ?>
	<configuration debug="true">

		<appender name="MONGODB"
			class="net.exacode.logback.classic.mongodb.MongoDbAppender">
			<host>localhost</host>
			<port>27017</port>
			<dbName>logsdb</dbName>
			<collectionName>logs</collectionName>
		</appender>

		<root level="DEBUG">
			<appender-ref ref="MONGODB" />
		</root>

	</configuration>

Maven dependency

In order to use this library add repository location into your pom.xml and add appropriate dependency.

	<dependency>
		<groupId>net.exacode.logback.classic</groupId>
		<artifactId>logback-extensions</artifactId>
		<version>${version.spring-logging}</version>
	</dependency>

Click here to lend your support to: Exacode open projects and make a donation at www.pledgie.com !

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages