forked from wiremock/wiremock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial merge of Rob's logging changes
Showing
13 changed files
with
194 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/github/tomakehurst/wiremock/Log4jConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.tomakehurst.wiremock; | ||
|
||
import org.apache.log4j.ConsoleAppender; | ||
import org.apache.log4j.Logger; | ||
import org.apache.log4j.PatternLayout; | ||
|
||
import com.github.tomakehurst.wiremock.common.Log4jNotifier; | ||
|
||
import static org.apache.log4j.Level.ERROR; | ||
import static org.apache.log4j.Level.INFO; | ||
import static org.apache.log4j.Level.TRACE; | ||
|
||
public class Log4jConfiguration { | ||
public static void configureLogging(boolean verbose) { | ||
ConsoleAppender appender = new ConsoleAppender(); | ||
appender.setLayout(new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %m%n")); | ||
if (verbose) { | ||
appender.setThreshold(INFO); | ||
} else { | ||
appender.setThreshold(ERROR); | ||
} | ||
|
||
appender.activateOptions(); | ||
Logger.getRootLogger().addAppender(appender); | ||
Logger.getRootLogger().setLevel(TRACE); | ||
if (verbose) { | ||
Logger.getLogger(Log4jNotifier.class).info("Verbose logging enabled"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>testlogging</groupId> | ||
<artifactId>testlogging</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<slf4jversion>1.7.1</slf4jversion> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>version99</id> | ||
<url>http://version99.qos.ch/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<!-- COMPILE --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4jversion}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<!-- TEST --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.tomakehurst</groupId> | ||
<artifactId>wiremock</artifactId> | ||
<version>1.30</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.0.7</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
<version>${slf4jversion}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jul-to-slf4j</artifactId> | ||
<version>${slf4jversion}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.org.lidalia</groupId> | ||
<artifactId>jul-to-slf4j-config</artifactId> | ||
<version>1.0.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>log4j-over-slf4j</artifactId> | ||
<version>${slf4jversion}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
<version>99-empty</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
<version>99-empty</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.3</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class WiremockTest { | ||
|
||
@Rule | ||
public WireMockRule wiremock = new WireMockRule(); | ||
|
||
@Test | ||
public void useWireMock() throws IOException { | ||
stubFor(get(urlMatching("/blah")).willReturn(aResponse().withStatus(200).withBody("body"))); | ||
URL uri = new URL("http://localhost:8080/blah"); | ||
InputStream content = uri.openConnection().getInputStream(); | ||
final String retrievedBody = IOUtils.toString(content); | ||
assertEquals("body", retrievedBody); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<configuration> | ||
<jmxconfigurator/> | ||
<contextlistener class="ch.qos.logback.classic.jul.LevelChangePropagator"/> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |