Skip to content

Commit

Permalink
java.util.logging instead of SLF4J, to avoid dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmugra committed Jan 2, 2021
1 parent 2414671 commit e7139fb
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 97 deletions.
11 changes: 0 additions & 11 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,11 @@

<dependencies>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
17 changes: 8 additions & 9 deletions core/src/main/java/net/cactusthorn/routing/RoutingServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.*;
import javax.servlet.http.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.cactusthorn.routing.EntryPointScanner.EntryPoint;
import net.cactusthorn.routing.RoutingConfig.ConfigProperty;
import net.cactusthorn.routing.PathTemplate.PathValues;
Expand All @@ -25,7 +24,7 @@ public class RoutingServlet extends HttpServlet {

private static final long serialVersionUID = 0L;

private static final Logger LOG = LoggerFactory.getLogger(RoutingServlet.class);
private static final Logger LOG = Logger.getLogger(RoutingServlet.class.getName());

private transient Map<Class<? extends Annotation>, List<EntryPoint>> allEntryPoints;
private transient ServletContext servletContext;
Expand Down Expand Up @@ -142,8 +141,8 @@ private String getPath(String contentType, HttpServletRequest req) {
} else if (!"/".equals(path) && path.charAt(path.length() - 1) != '/') {
path += '/';
}
LOG.debug("{}({} {}) PathInfo -> original: \"{}\", corrected: \"{}\"", req.getMethod(), contentType, req.getCharacterEncoding(),
original, path);
LOG.log(Level.FINE, "{0}({1} {2}) PathInfo -> original: \"{3}\", corrected: \"{4}\"",
new Object[] {req.getMethod(), contentType, req.getCharacterEncoding(), original, path});
return path;
}

Expand All @@ -156,7 +155,7 @@ private void produce(HttpServletRequest req, HttpServletResponse resp, EntryPoin
String contentType = entryPoint.produces();
resp.setContentType(contentType);
producers.get(contentType).produce(result, entryPoint.template(), contentType, req, resp);
LOG.debug("Producer processing done for Content-Type: {}", contentType);
LOG.log(Level.FINE, "Producer processing done for Content-Type: {0}", new Object[] {contentType});
}

private void produce(HttpServletRequest req, HttpServletResponse resp, EntryPoint entryPoint, Response response) throws IOException {
Expand Down Expand Up @@ -187,10 +186,10 @@ private void produce(HttpServletRequest req, HttpServletResponse resp, EntryPoin
if (response.body() != null) {
resp.getWriter().write(String.valueOf(response.body()));
}
LOG.debug("Producer processing skipped!");
LOG.fine("Producer processing skipped!");
return;
}
producers.get(contentType).produce(response.body(), template, contentType, req, resp);
LOG.debug("Producer processing done for Content-Type: {}", contentType);
LOG.log(Level.FINE, "Producer processing done for Content-Type: {0}", new Object[] {contentType});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.cactusthorn.routing.producer;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -9,13 +10,16 @@ public class TextPlainProducer implements Producer {

public static final String MEDIA_TYPE = "text/plain";

private static final Logger LOG = Logger.getLogger(TextPlainProducer.class.getName());

@Override //
public void produce(Object object, String template, String mediaType, HttpServletRequest req, HttpServletResponse resp)
throws IOException {
if (object == null) {
if (resp.getStatus() == HttpServletResponse.SC_OK) {
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
LOG.fine("NO CONTENT");
return;
}
resp.getWriter().write(String.valueOf(object));
Expand Down
17 changes: 0 additions & 17 deletions core/src/test/resources/logback-test.xml

This file was deleted.

11 changes: 8 additions & 3 deletions demo-jetty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>net.cactusthorn.routing</groupId>
<artifactId>json-gson</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>net.cactusthorn.routing</groupId>
<artifactId>thymeleaf</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>net.cactusthorn.routing</groupId>
<artifactId>validation-javax</artifactId>
Expand All @@ -51,6 +48,14 @@
<artifactId>dagger</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.security.Principal;
import java.time.LocalDate;
import java.util.EnumSet;
import java.util.logging.Level;

import javax.servlet.DispatcherType;
import javax.servlet.Filter;
Expand All @@ -29,13 +30,19 @@
import org.eclipse.jetty.util.resource.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

public class Application {

private static final Logger LOG = LoggerFactory.getLogger(Application.class);

public static void main(String... args) {

// java.util.loggingg -> SLF4j
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
java.util.logging.Logger.getLogger("").setLevel(Level.FINEST);

HandlerList handlers = new HandlerList();
handlers.addHandler(createStaticResourcesServlet());
handlers.addHandler(createRoutingServlet());
Expand Down
6 changes: 0 additions & 6 deletions json-gson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
<artifactId>gson</artifactId>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonWriter;
Expand All @@ -16,8 +13,6 @@

public class SimpleGsonProducer implements Producer {

private static final Logger LOG = LoggerFactory.getLogger(SimpleGsonProducer.class);

private Gson gson;

public SimpleGsonProducer(Gson gson) {
Expand All @@ -32,7 +27,6 @@ public SimpleGsonProducer() {
public void produce(Object object, String template, String mediaType, HttpServletRequest req, HttpServletResponse resp)
throws IOException {
if (object == null) {
LOG.warn("Entry point return Object is NULL");
if (resp.getStatus() == HttpServletResponse.SC_OK) {
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
Expand Down
17 changes: 0 additions & 17 deletions json-gson/src/test/resources/logback-test.xml

This file was deleted.

16 changes: 10 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@
<dependencyManagement>
<dependencies>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${dependency.slf4j}</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down Expand Up @@ -182,6 +176,16 @@
<version>${dependency.dagger}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${dependency.slf4j}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${dependency.slf4j}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.thymeleaf.ITemplateEngine;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.templatemode.TemplateMode;
Expand All @@ -21,8 +19,6 @@

public class SimpleThymeleafProducer implements Producer {

private static final Logger LOG = LoggerFactory.getLogger(SimpleThymeleafProducer.class);

private ITemplateEngine templateEngine;

public SimpleThymeleafProducer(ITemplateEngine templateEngine) {
Expand Down Expand Up @@ -69,7 +65,6 @@ public void produce(Object object, String template, String mediaType, HttpServle
}

templateEngine.process(template, ctx, resp.getWriter());
LOG.debug("processed template: {}", template);
}

}
17 changes: 0 additions & 17 deletions thymeleaf/src/test/resources/logback-test.xml

This file was deleted.

0 comments on commit e7139fb

Please sign in to comment.