forked from yegor256/takes
-
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.
- Loading branch information
Showing
13 changed files
with
200 additions
and
648 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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"); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.