mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add log api
This commit is contained in:
@@ -17,6 +17,8 @@ package com.alibaba.druid.pool;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
* @since 0.2.19
|
||||
@@ -30,4 +32,8 @@ public interface DruidDataSourceStatLogger {
|
||||
* @since 0.2.21
|
||||
*/
|
||||
void configFromProperties(Properties properties);
|
||||
|
||||
void setLogger(Log logger);
|
||||
|
||||
void setLoggerName(String loggerName);
|
||||
}
|
||||
|
||||
@@ -17,12 +17,14 @@ package com.alibaba.druid.pool;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
* @since 0.2.21
|
||||
*/
|
||||
public abstract class DruidDataSourceStatLoggerAdapter implements DruidDataSourceStatLogger {
|
||||
public class DruidDataSourceStatLoggerAdapter implements DruidDataSourceStatLogger {
|
||||
|
||||
@Override
|
||||
public void log(DruidDataSourceStatValue statValue) {
|
||||
@@ -34,4 +36,14 @@ public abstract class DruidDataSourceStatLoggerAdapter implements DruidDataSourc
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogger(Log logger) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoggerName(String loggerName) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,20 +56,30 @@ public class DruidDataSourceStatLoggerImpl extends DruidDataSourceStatLoggerAdap
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoggerName(String loggerName) {
|
||||
logger = LogFactory.getLog(loggerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogger(Log logger) {
|
||||
if (logger == null) {
|
||||
throw new IllegalArgumentException("logger can not be null");
|
||||
}
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public boolean isLogEnable() {
|
||||
return logger.isInfoEnabled();
|
||||
}
|
||||
|
||||
public void log(String value) {
|
||||
logger.info(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(DruidDataSourceStatValue statValue) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
if (isLogEnable()) {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
|
||||
map.put("url", statValue.url);
|
||||
@@ -225,7 +235,7 @@ public class DruidDataSourceStatLoggerImpl extends DruidDataSourceStatLoggerAdap
|
||||
|
||||
String text = JSONUtils.toJSONString(map);
|
||||
|
||||
logger.info(text);
|
||||
log(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ public class SLF4JImpl implements Log {
|
||||
private int infoCount;
|
||||
private LocationAwareLogger log;
|
||||
|
||||
public SLF4JImpl(Class<?> clazz){
|
||||
this.log = (LocationAwareLogger) LoggerFactory.getLogger(clazz);
|
||||
public SLF4JImpl(LocationAwareLogger log){
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
|
||||
public SLF4JImpl(String loggerName){
|
||||
this.log = (LocationAwareLogger) LoggerFactory.getLogger(loggerName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user