Skip to content

Commit

Permalink
Commit more providers
Browse files Browse the repository at this point in the history
  • Loading branch information
wsargent committed Jul 5, 2019
1 parent 32d88ca commit abdcf33
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions logback-json-exception-mapping/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project_description = Extra exception mapping providers
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
dependencies {
compile project(':logback-exception-mapping')
compile project(':logback-typesafe-config')

compile "net.logstash.logback:logstash-logback-encoder:$logstashVersion"
}

config {
javadoc {
options.charSet = 'UTF-8'
options.encoding = 'UTF-8'
options.docEncoding = 'UTF-8'
options.use = true
options.links = [jvmToJavadoc(targetCompatibility)] + javadocFromDependencies(configurations.compile)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tersesystems.logback.structuredconfig;
package com.tersesystems.logback.exceptionmapping;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.tersesystems.logback.exceptionmapping;

import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.spi.ActionException;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import com.tersesystems.logback.exceptionmapping.ExceptionMappingRegistry;
import com.tersesystems.logback.typesafeconfig.ConfigConstants;
import com.typesafe.config.Config;
import org.xml.sax.Attributes;

import java.util.List;
import java.util.Map;

public class TypesafeConfigMappings extends Action {

@SuppressWarnings("unchecked")
private ExceptionMappingRegistry getRegistry(InterpretationContext ic) {
Object obj = ic.peekObject();
if (obj == null) {
addError("Not in an exception registry");
return null;
}

if (obj instanceof ExceptionMappingRegistry) {
return (ExceptionMappingRegistry) obj;
}
return null;
}

@Override
public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException {
ExceptionMappingRegistry registry = getRegistry(ic);
Config config = getConfig(ic);

if (registry != null && config != null) {
Map<String, List<String>> mappings = getMappingsFromConfig();
registry.register(mappings);
}
}

private Config getConfig(InterpretationContext ic) {
Object obj = ic.getObjectMap().get(ConfigConstants.TYPESAFE_CONFIG_CTX_KEY);
if (obj == null) {
addError("No typesafe config found in object map!");
return null;
}
if (obj instanceof Config) {
return (Config) obj;
}
return null;
}

@Override
public void end(InterpretationContext ic, String name) throws ActionException {

}

public Map<String, List<String>> getMappingsFromConfig() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tersesystems.logback.exceptionmapping.json;

public class ExceptionArgumentsProviderTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tersesystems.logback.exceptionmapping.json;

public class TypesafeConfigMappingsTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<logstashMarkers/>
<arguments/>

<provider class="com.tersesystems.logback.structuredconfig.ExceptionArgumentsProvider">
<provider class="structuredconfig.ExceptionArgumentsProvider">
<fieldName>exception</fieldName>
<!-- Any properties exposed by your provider can be set here -->
</provider>
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ includeProject 'logback-compress-encoder'
includeProject 'logback-budget'
includeProject 'logback-uniqueid-appender'
includeProject 'logback-exception-mapping'
includeProject 'logback-json-exception-mapping'
//includeProject 'guide'

0 comments on commit abdcf33

Please sign in to comment.