airbrake-logback

Logback Appender for Airbrake

License

License

Categories

Categories

Ant Build Tools Net Logback Application Layer Libs Logging
GroupId

GroupId

net.anthavio
ArtifactId

ArtifactId

airbrake-logback
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

airbrake-logback
Logback Appender for Airbrake
Project Organization

Project Organization

Anthavio
Source Code Management

Source Code Management

https://github.com/anthavio/airbrake-logback

Download airbrake-logback

How to add to project

<!-- https://jarcasting.com/artifacts/net.anthavio/airbrake-logback/ -->
<dependency>
    <groupId>net.anthavio</groupId>
    <artifactId>airbrake-logback</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/net.anthavio/airbrake-logback/
implementation 'net.anthavio:airbrake-logback:1.0.3'
// https://jarcasting.com/artifacts/net.anthavio/airbrake-logback/
implementation ("net.anthavio:airbrake-logback:1.0.3")
'net.anthavio:airbrake-logback:jar:1.0.3'
<dependency org="net.anthavio" name="airbrake-logback" rev="1.0.3">
  <artifact name="airbrake-logback" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.anthavio', module='airbrake-logback', version='1.0.3')
)
libraryDependencies += "net.anthavio" % "airbrake-logback" % "1.0.3"
[net.anthavio/airbrake-logback "1.0.3"]

Dependencies

compile (3)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.1.1
javax.servlet : servlet-api Optional jar 2.4
io.airbrake : airbrake-java jar 2.2.8

test (4)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 1.7.1
org.mockito : mockito-all jar 1.10.19
org.springframework : spring-test jar 3.2.18.RELEASE

Project Modules

There are no modules declared in this project.

airbrake-logback

Build Status Coverage Status Maven Central

Logback Appender for Airbrake

Built on the top of the official airbrake.io library adding Logback Appender

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true" scanPeriod="30 seconds">

	<appender name="AIRBRAKE" class="net.anthavio.airbrake.AirbrakeLogbackAppender">
		<apiKey>YOUR_AIRBRAKE_API_KEY</apiKey>
		<env>test</env>
		<enabled>true</enabled>

		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>ERROR</level>
		</filter>
	</appender>

	<root>
		<level value="info" />
		<appender-ref ref="AIRBRAKE" />
	</root>
	
</configuration>

Additionaly to airbrake.io library functionality, airbrake-logback also can send simple one line error messages without stacktraces. Source code line, where error was logged, is still captured and sent to Airbrake.

Configure it setting <notify>ALL</notify> in logback.xml Possible values are ALL, EXCEPTIONS, OFF

	<appender name="AIRBRAKE" class="net.anthavio.airbrake.AirbrakeLogbackAppender">
		<apiKey>YOUR_AIRBRAKE_API_KEY</apiKey>
		<env>test</env>
		<notify>ALL</notify>
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>ERROR</level>
		</filter>
	</appender>

Java code

Logger logger = LoggerFactory.getLogger(getClass());
logger.error("I'm going to Airbrake! Exact line will be there too");

HTTP request and session integration

If you happen to use library in Servlet container you can have HTTP request and session information included in Airbrake notifications. To enable it you have to add AirbrakeServletRequestFilter into your configuration web.xml exmple

  <filter> 
    <filter-name>AirbrakeFilter</filter-name>
    <filter-class>net.anthavio.airbrake.http.AirbrakeServletRequestFilter</filter-class> 
  </filter> 
  <filter-mapping> 
    <filter-name>AirbrakeFilter</filter-name>
    <url-pattern>/*</url-pattern> 
  </filter-mapping> 

Spring Boot @Configuration example

	@Bean
	public FilterRegistrationBean airbrakeFilter() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(new AirbrakeServletRequestFilter());
		registration.addUrlPatterns("/*");
		return registration;
	}

In case you are unhappy with provided AirbrakeServletRequestFilter and HttpServletRequestEnhancer, you can implement your own...

package com.example;
import net.anthavio.airbrake.AirbrakeNoticeBuilderUsingFilteredSystemProperties;
import net.anthavio.airbrake.http.RequestEnhancer;
import net.anthavio.airbrake.http.RequestEnhancerFactory;

// Simpe example implementation
public class HackyEnhancerFactory implements RequestEnhancerFactory {

    @Override
    public RequestEnhancer get() {
        return new HackyEnhancer();
    }

    static class HackyEnhancer implements RequestEnhancer<Void> {

        @Override
        public void setRequest(Void request) {
            // nothing
        }

        @Override
        public void endRequest(Void request) {
            // nothing
        }

        @Override
        public void enhance(AirbrakeNoticeBuilderUsingFilteredSystemProperties builder) {
            builder.setRequest("http://localhost","");
        }
    }
}

and then configure it in logback.xml using

	<appender name="AIRBRAKE" class="net.anthavio.airbrake.AirbrakeLogbackAppender">
		<apiKey>YOUR_AIRBRAKE_API_KEY</apiKey>
		<env>test</env>
		<notify>ALL</notify>
		<requestEnhancerFactory>com.example.HackyEnhancerFactory</requestEnhancerFactory>
		
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>ERROR</level>
		</filter>
	</appender>

Versions

Version
1.0.3
1.0.2
1.0.1
1.0.0