Skip to content

Commit

Permalink
yegor256#28 fix CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dmzaytsev committed Mar 29, 2015
1 parent 1f4bb7c commit ed23f4d
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/takes/facets/slf4j/BkLogged.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class BkLogged extends LogWrap implements Back {
* @param back Original
*/
public BkLogged(final Back back) {
this(back, LogWrap.Level.TRACE);
this(back, LogWrap.DEFAULT_LEVEL);
}

/**
Expand All @@ -66,7 +66,7 @@ public void accept(final Socket socket) throws IOException {
final long started = System.currentTimeMillis();
this.origin.accept(socket);
this.log(
"[%s] #accept(%s) in [%d] ms",
"[{}] #accept([{}]) in [{}] ms",
this.origin,
socket,
System.currentTimeMillis() - started
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/takes/facets/slf4j/FtLogged.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class FtLogged extends LogWrap implements Front {
* @param front Original
*/
public FtLogged(final Front front) {
this(front, LogWrap.Level.TRACE);
this(front, LogWrap.DEFAULT_LEVEL);
}

/**
Expand All @@ -64,7 +64,7 @@ public FtLogged(final Front front, final LogWrap.Level lvl) {
@Override
public void start(final Exit exit) throws IOException {
this.log(
"[%s] #start(%s)",
"[{}] #start([{}])",
this.origin,
exit
);
Expand Down
56 changes: 33 additions & 23 deletions src/main/java/org/takes/facets/slf4j/LogWrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@
* @version $Id$
* @since 0.11
*/
@SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.LoggerIsNotStaticFinal" })
@SuppressWarnings("PMD.LoggerIsNotStaticFinal")
public class LogWrap {
/**
* Default log level.
*/
public static final LogWrap.Level DEFAULT_LEVEL = LogWrap.Level.DEBUG;
/**
* Log levels.
*/
Expand All @@ -58,9 +62,9 @@ public enum Level {
*/
WARN,
/**
* Severe level.
* Error level.
*/
SEVERE
ERROR
};

/**
Expand All @@ -73,6 +77,14 @@ public enum Level {
*/
private final transient Logger logger;

/**
* Ctor.
* @param clazz Logger class
*/
public LogWrap(final Class<?> clazz) {
this(clazz, LogWrap.Level.DEBUG);
}

/**
* Ctor.
* @param clazz Logger class
Expand All @@ -87,28 +99,26 @@ public LogWrap(final Class<?> clazz, final LogWrap.Level lvl) {
* Log message.
* @param format Format string
* @param param Parameters
* @checkstyle CyclomaticComplexityCheck (2 line)
*/
public final void log(final String format, final Object... param) {
if (this.level == LogWrap.Level.TRACE
&& this.logger.isTraceEnabled()) {
this.logger.trace(String.format(format, param));
} else if (
this.level == LogWrap.Level.DEBUG
&& this.logger.isDebugEnabled()) {
this.logger.debug(String.format(format, param));
} else if (
this.level == LogWrap.Level.INFO
&& this.logger.isInfoEnabled()) {
this.logger.trace(String.format(format, param));
} else if (
this.level == LogWrap.Level.WARN
&& this.logger.isWarnEnabled()) {
this.logger.warn(String.format(format, param));
} else if (
this.level == LogWrap.Level.SEVERE
&& this.logger.isErrorEnabled()) {
this.logger.error(String.format(format, param));
switch (this.level) {
case TRACE :
this.logger.trace(format, param);
break;
case DEBUG:
this.logger.debug(format, param);
break;
case INFO:
this.logger.info(format, param);
break;
case WARN:
this.logger.warn(format, param);
break;
case ERROR:
this.logger.error(format, param);
break;
default:
throw new IllegalArgumentException("Unknown log level");
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/takes/facets/slf4j/PsLogged.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class PsLogged extends LogWrap implements Pass {
* @param pass Original
*/
public PsLogged(final Pass pass) {
this(pass, LogWrap.Level.TRACE);
this(pass, LogWrap.DEFAULT_LEVEL);
}

/**
Expand All @@ -80,7 +80,7 @@ public Iterator<Identity> enter(final Request request) throws IOException {
}
sbr.append(']');
this.log(
"[%s] #enter(%s) return [%s] in [%d] ms",
"[{}] #enter({}) return [{}] in [{}] ms",
this.origin,
request,
sbr.toString(),
Expand All @@ -95,7 +95,7 @@ public Response exit(final Response response, final Identity identity)
final long started = System.currentTimeMillis();
final Response resp = this.origin.exit(response, identity);
this.log(
"[%s] #exit(%s,%s) return [%s] in [%d] ms",
"[{}] #exit([{}],[{}]) return [{}] in [{}] ms",
this.origin,
response,
identity,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/takes/facets/slf4j/TkLogged.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class TkLogged extends LogWrap implements Take {
* @param take Original
*/
public TkLogged(final Take take) {
this(take, LogWrap.Level.TRACE);
this(take, LogWrap.DEFAULT_LEVEL);
}

/**
Expand All @@ -66,7 +66,7 @@ public Response act() throws IOException {
final long started = System.currentTimeMillis();
final Response resp = this.origin.act();
this.log(
"[%s] #act() return [%s] in [%d] ms",
"[{}] #act() return [{}] in [{}] ms",
this.origin,
resp,
System.currentTimeMillis() - started
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/takes/facets/slf4j/TsLogged.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class TsLogged extends LogWrap implements Takes {
* @param takes Original
*/
public TsLogged(final Takes takes) {
this(takes, LogWrap.Level.TRACE);
this(takes, LogWrap.DEFAULT_LEVEL);
}

/**
Expand All @@ -68,7 +68,7 @@ public Take route(final Request request) throws IOException {
final long started = System.currentTimeMillis();
final Take resp = this.origin.route(request);
this.log(
"[%s] #route(%s) return [%s] in [%d] ms",
"[{}] #route([{}]) return [{}] in [{}] ms",
this.origin,
request,
resp,
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/org/takes/facets/slf4j/BkLoggedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public final class BkLoggedTest {
/**
* BkLogged can log message.
* @throws IOException If some problem inside
* @todo #90 we should change mocked Log4j appender to
* custom Log4jAppeneder that implemented as JUnit Rule.
* See details in CR comment here
* https://github.com/yegor256/takes/pull/89#discussion_r27354036
*/
@Test
public void logsMessage() throws IOException {
Expand All @@ -67,7 +71,7 @@ public void accept(final Socket socket) throws IOException {
public boolean matches(final Object argument) {
return ((LoggingEvent) argument)
.getRenderedMessage()
.matches("^.*accept.*$");
.contains("accept");
}
}
)
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/org/takes/facets/slf4j/FtLoggedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public final class FtLoggedTest {
/**
* FtLogged can log message.
* @throws IOException If some problem inside
* @todo #90 we should change mocked Log4j appender to
* custom Log4jAppeneder that implemented as JUnit Rule.
* See details in CR comment here
* https://github.com/yegor256/takes/pull/89#discussion_r27354036
*/
@Test
public void logsMessage() throws IOException {
Expand Down Expand Up @@ -75,7 +79,7 @@ public boolean ready() {
public boolean matches(final Object argument) {
return ((LoggingEvent) argument)
.getRenderedMessage()
.matches("^.*start.*$");
.contains("start");
}
}
)
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/takes/facets/slf4j/PsLoggedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public final class PsLoggedTest {
/**
* PsLogged can log message.
* @throws IOException If some problem inside
* @todo #90 we should change mocked Log4j appender to
* custom Log4jAppeneder that implemented as JUnit Rule.
* See details in CR comment here
* https://github.com/yegor256/takes/pull/89#discussion_r27354036
*/
@Test
public void logsMessage() throws IOException {
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/org/takes/facets/slf4j/TkLoggedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public final class TkLoggedTest {
/**
* TkLogged can log message.
* @throws IOException If some problem inside
* @todo #90 we should change mocked Log4j appender to
* custom Log4jAppeneder that implemented as JUnit Rule.
* See details in CR comment here
* https://github.com/yegor256/takes/pull/89#discussion_r27354036
*/
@Test
public void logsMessage() throws IOException {
Expand All @@ -59,7 +63,7 @@ public void logsMessage() throws IOException {
public boolean matches(final Object argument) {
return ((LoggingEvent) argument)
.getRenderedMessage()
.matches("^.*act().*$");
.contains("act()");
}
}
)
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/org/takes/facets/slf4j/TsLoggedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public final class TsLoggedTest {
/**
* TsLogged can log message.
* @throws IOException If some problem inside
* @todo #90 we should change mocked Log4j appender to
* custom Log4jAppeneder that implemented as JUnit Rule.
* See details in CR comment here
* https://github.com/yegor256/takes/pull/89#discussion_r27354036
*/
@Test
public void logsMessage() throws IOException {
Expand Down Expand Up @@ -74,7 +78,7 @@ public String toString() {
public boolean matches(final Object argument) {
return ((LoggingEvent) argument)
.getRenderedMessage()
.matches("^.*FakeTakes.*$");
.contains("[FakeTakes]");
}
}
)
Expand Down

0 comments on commit ed23f4d

Please sign in to comment.