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 ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;
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);

        appender.start();

        Appender asyncAppender = wrapAsync(appender);
        addThresholdFilter(asyncAppender, threshold);
        addDroppingRavenLoggingFilter(asyncAppender);

        return asyncAppender;
    }

    public void addDroppingRavenLoggingFilter(Appender appender) {
        Filter filter = new DroppingRavenLoggingFilter();
        filter.start();
        appender.addFilter(filter);
    }

    public static class DroppingRavenLoggingFilter extends Filter<ILoggingEvent> {

        @Override
        public FilterReply decide(ILoggingEvent event) {
            if (event.getLoggerName().startsWith("net.kencochrane.raven")) {
                return FilterReply.DENY;
            } else {
                return FilterReply.ACCEPT;
            }
        }
    }
}

@@ -29,16 +29,188 @@
 gging;%0A%0A
+import static com.google.common.base.Preconditions.checkNotNull;%0Aimport io.dropwizard.logging.AbstractAppenderFactory;%0Aimport net.kencochrane.raven.logback.SentryAppender;%0A
 import c
@@ -246,16 +246,16 @@
 ontext;%0A
-
 import c
@@ -453,16 +453,17 @@
 rReply;%0A
+%0A
 import c
@@ -566,181 +566,8 @@
 me;%0A
-import io.dropwizard.logging.AbstractAppenderFactory;%0Aimport net.kencochrane.raven.logback.SentryAppender;%0A%0Aimport static com.google.common.base.Preconditions.checkNotNull;%0A
 %0A%0A%0A@
@@ -1357,16 +1357,31 @@
 Appender
+%3CILoggingEvent%3E
  asyncAp
@@ -1602,32 +1602,47 @@
 gFilter(Appender
+%3CILoggingEvent%3E
  appender) %7B%0A   
@@ -1652,16 +1652,31 @@
   Filter
+%3CILoggingEvent%3E
  filter 

apply generics to DroppingRavenLoggingFilter changes