spring-Logging
本文记录spring logging 的原理与配置
framework logging
Spring Boot uses Commons Logging
for all internal logging but leaves the underlying log implementation open.
in spring-jcl
package
LogFactory
is a minimal incarnation of Apache Commons Logging api, it provides log lookup method.
LogAdaper
detects the presence of log4j 2.x/slf4j
1. log4j2 detection by org.apache.logging.log4j.spi.ExtendedLogger
interface Log {
void info(Object message)
void info(Object message, Throwable t)
}
abstract class LogFactory {
{static} Log getLog()
}
class LogAdapter {
boolean log4jSpiPresent
}
class Log4jAdapter {
Log createLog(String name)
}
class Log4jLog implements Log {
{static} LoggerContext loggerContext
String name
ExtendedLogger logger
}
LogFactory --> LogAdapter: detect
LogAdapter --> Log4jAdapter : createLog
Log4jAdapter -down-> Log4jLog : new
slf4j logging
slf4j
use SLF4JServiceProvider
SPI to detect available loggings in class path.
class LoggerFactory {
static List<SLF4JServiceProvider> findServiceProviders()
}