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 31, 2015
1 parent ed23f4d commit 89d3e04
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 648 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>
<build>
Expand Down
75 changes: 0 additions & 75 deletions src/main/java/org/takes/facets/slf4j/BkLogged.java

This file was deleted.

107 changes: 0 additions & 107 deletions src/main/java/org/takes/facets/slf4j/PsLogged.java

This file was deleted.

145 changes: 145 additions & 0 deletions src/main/java/org/takes/facets/slf4j/Slf4j.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.takes.facets.slf4j;

import lombok.EqualsAndHashCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Slf4j target.
*
* <p>The class is immutable and thread-safe.
* @author Dmitry Zaytsev (dmitry.zaytsev@gmail.com)
* @version $Id$
* @since 0.11.2
*/
@EqualsAndHashCode(of = "logger")
@SuppressWarnings("PMD.LoggerIsNotStaticFinal")
public final class Slf4j implements Target {
/**
* Default log level.
*/
public static final Slf4j.Level DEFAULT_LEVEL = Slf4j.Level.DEBUG;

/**
* Log levels.
*/
public enum Level {
/**
* Trace level.
*/
TRACE,
/**
* Debug level.
*/
DEBUG,
/**
* Info level.
*/
INFO,
/**
* Warn level.
*/
WARN,
/**
* Error level.
*/
ERROR
};

/**
* Log level.
*/
private final transient Slf4j.Level level;

/**
* Logger.
*/
private transient Logger logger;

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

/**
* Ctor.
* @param name Logger name
*/
public Slf4j(final String name) {
this(name, Slf4j.DEFAULT_LEVEL);
}

/**
* Ctor.
* @param clazz Logger class
* @param lvl Log level
*/
public Slf4j(final Class<?> clazz, final Slf4j.Level lvl) {
this(clazz.getName(), lvl);
}

/**
* Ctor.
* @param name Logger name
* @param lvl Log level
*/
public Slf4j(final String name, final Slf4j.Level lvl) {
this.level = lvl;
this.logger = LoggerFactory.getLogger(name);
}

/**
* Log message.
* @param format Format string
* @param param Parameters
*/
@Override
public void log(final String format, final Object... 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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,19 @@

package org.takes.facets.slf4j;

import java.io.IOException;
import lombok.EqualsAndHashCode;
import org.takes.http.Exit;
import org.takes.http.Front;

/**
* Logs Front.start() calls.
* Log target.
*
* <p>The class is immutable and thread-safe.
* <p>All implementations of this interface must be immutable and thread-safe.
* @author Dmitry Zaytsev (dmitry.zaytsev@gmail.com)
* @version $Id$
* @since 0.11
*/
@EqualsAndHashCode(of = "origin", callSuper = false)
public final class FtLogged extends LogWrap implements Front {
/**
* Original front.
*/
private final transient Front origin;

public interface Target {
/**
* Ctor.
* @param front Original
* SLF4J parameterized logging.
* @param format Format string
* @param param Params
*/
public FtLogged(final Front front) {
this(front, LogWrap.DEFAULT_LEVEL);
}

/**
* Ctor.
* @param front Original
* @param lvl Log level
*/
public FtLogged(final Front front, final LogWrap.Level lvl) {
super(front.getClass(), lvl);
this.origin = front;
}

@Override
public void start(final Exit exit) throws IOException {
this.log(
"[{}] #start([{}])",
this.origin,
exit
);
this.origin.start(exit);
}
void log(final String format, final Object... param);
}
Loading

0 comments on commit 89d3e04

Please sign in to comment.