add log api

This commit is contained in:
wenshao
2013-06-03 16:33:44 +08:00
parent c30f85b1c1
commit 3995dfa7a3
4 changed files with 34 additions and 6 deletions
@@ -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);
}