The library I added in Gradle's dependency uses a logging framework called SLF4J. You may see an error when you run the program. Here, make a note of how to deal with it.
Failed to load class
If the library added as a dependency uses SLF4J, the following error may be thrown.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
This means that there is no logger that implements StaticLoggerBinder. In SLF4J, the log implementation to be used is specified by a class called StaticLoggerBinder. So let's add a logger (Log4J) that implements StaticLoggerBinder to the dependency.
build.gradle
dependencies {
compile 'org.slf4j:slf4j-log4j12:1.7.21'
}
WARN No appenders could be found for logger
When I add a logger (Log4J) that implements StatucLoggerBinder to the dependency and execute the program, the following warning is issued.
log4j:WARN No appenders could be found for logger (xxxxxxx).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
This means that Appender is not set for the class that outputs logs.
So let's create a Log4J config file and place it in the project's src / main / resources
.
I want to output the log in the development environment, but in the production environment it may not be necessary to output the log, so Make a note of the settings for outputting logs and not outputting logs.
log4j.properties
log4j.rootLogger=DEBUG, console
log4j.logger.xxx=DEBUG, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d [%-5p-%c] %m%n
log4j.properties
log4j.rootLogger=FATAL, null
log4j.appender.null=org.apache.log4j.varia.NullAppender
Recommended Posts