package com.tradier.raven.logging;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Appender;
import ch.qos.logback.core.Layout;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.dropwizard.logging.AbstractAppenderFactory;
import net.kencochrane.raven.logback.SentryAppender;

import static com.google.common.base.Preconditions.checkNotNull;

@JsonTypeName("raven")
public class RavenAppenderFactory extends AbstractAppenderFactory {

	@JsonProperty
	private String dsn = null;

    @JsonProperty
    private String tags = null;

    public String getDsn() {
		return dsn;
	}

	public void setDsn(String dsn) {
		this.dsn = dsn;
	}

	public String getTags() {
		return tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	@Override
    public Appender<ILoggingEvent> build(LoggerContext context, String applicationName, Layout<ILoggingEvent> layout) {
        checkNotNull(context);

        final SentryAppender appender = new SentryAppender();

        appender.setContext(context);
        appender.setDsn(dsn);
        if(tags != null)
        	appender.setTags(tags);

        addThresholdFilter(appender, threshold);
        appender.start();

        return wrapAsync(appender);
    }
}

@@ -195,16 +195,102 @@
 Layout;%0A
+import ch.qos.logback.core.filter.Filter;%0Aimport ch.qos.logback.core.spi.FilterReply;%0A
 import c
@@ -563,16 +563,18 @@
 tNull;%0A%0A
+%0A%0A
 @JsonTyp
@@ -1310,24 +1310,105 @@
 ags(tags);%0A%0A
+        appender.start();%0A%0A        Appender asyncAppender = wrapAsync(appender);%0A
         addT
@@ -1423,16 +1423,21 @@
 Filter(a
+syncA
 ppender,
@@ -1462,61 +1462,647 @@
    a
-ppender.start();%0A
+ddDroppingRavenLoggingFilter(asyncAppender);%0A%0A        return asyncAppender;%0A    %7D%0A%0A    public void addDroppingRavenLoggingFilter(Appender appender) %7B%0A        Filter filter = new DroppingRavenLoggingFilter();%0A        filter.start();%0A        appender.addFilter(filter);
 %0A    
+%7D%0A%0A
     
-return wrapAsync(appender);
+public static class DroppingRavenLoggingFilter extends Filter%3CILoggingEvent%3E %7B%0A%0A        @Override%0A        public FilterReply decide(ILoggingEvent event) %7B%0A            if (event.getLoggerName().startsWith(%22net.kencochrane.raven%22)) %7B%0A                return FilterReply.DENY;%0A            %7D else %7B%0A                return FilterReply.ACCEPT;%0A            %7D%0A        %7D
 %0A   

Drop any log events coming from the Raven package