mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@78 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
package com.alibaba.druid.filter.logging;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class Slf4jLogFilter extends LogFilter {
|
||||
private String dataSourceLoggerName = "druid.sql.DataSource";
|
||||
private String connectionLoggerName = "druid.sql.Connection";
|
||||
private String statementLoggerName = "druid.sql.Statement";
|
||||
private String resultSetLoggerName = "druid.sql.ResultSet";
|
||||
|
||||
private Logger dataSourceLogger = LoggerFactory.getLogger(dataSourceLoggerName);
|
||||
private Logger connectionLogger = LoggerFactory.getLogger(connectionLoggerName);
|
||||
private Logger statementLogger = LoggerFactory.getLogger(statementLoggerName);
|
||||
private Logger resultSetLogger = LoggerFactory.getLogger(resultSetLoggerName);
|
||||
|
||||
@Override
|
||||
public String getDataSourceLoggerName() {
|
||||
return dataSourceLoggerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDataSourceLoggerName(String dataSourceLoggerName) {
|
||||
this.dataSourceLoggerName = dataSourceLoggerName;
|
||||
dataSourceLogger = LoggerFactory.getLogger(dataSourceLoggerName);
|
||||
}
|
||||
|
||||
public void setDataSourceLogger(Logger dataSourceLogger) {
|
||||
this.dataSourceLogger = dataSourceLogger;
|
||||
this.dataSourceLoggerName = dataSourceLogger.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionLoggerName() {
|
||||
return connectionLoggerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectionLoggerName(String connectionLoggerName) {
|
||||
this.connectionLoggerName = connectionLoggerName;
|
||||
connectionLogger = LoggerFactory.getLogger(connectionLoggerName);
|
||||
}
|
||||
|
||||
public void setConnectionLogger(Logger connectionLogger) {
|
||||
this.connectionLogger = connectionLogger;
|
||||
this.connectionLoggerName = connectionLogger.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatementLoggerName() {
|
||||
return statementLoggerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatementLoggerName(String statementLoggerName) {
|
||||
this.statementLoggerName = statementLoggerName;
|
||||
statementLogger = LoggerFactory.getLogger(statementLoggerName);
|
||||
}
|
||||
|
||||
public void setStatementLogger(Logger statementLogger) {
|
||||
this.statementLogger = statementLogger;
|
||||
this.statementLoggerName = statementLogger.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResultSetLoggerName() {
|
||||
return resultSetLoggerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResultSetLoggerName(String resultSetLoggerName) {
|
||||
this.resultSetLoggerName = resultSetLoggerName;
|
||||
resultSetLogger = LoggerFactory.getLogger(resultSetLoggerName);
|
||||
}
|
||||
|
||||
public void setResultSetLogger(Logger resultSetLogger) {
|
||||
this.resultSetLogger = resultSetLogger;
|
||||
this.resultSetLoggerName = resultSetLogger.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectionLogErrorEnabled() {
|
||||
return connectionLogger.isErrorEnabled() && super.isConnectionLogErrorEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataSourceLogEnabled() {
|
||||
return dataSourceLogger.isDebugEnabled() && super.isDataSourceLogEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectionLogEnabled() {
|
||||
return connectionLogger.isDebugEnabled() && super.isConnectionLogEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStatementLogEnabled() {
|
||||
return statementLogger.isDebugEnabled() && super.isStatementLogEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isResultSetLogEnabled() {
|
||||
return resultSetLogger.isDebugEnabled() && super.isResultSetLogEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isResultSetLogErrorEnabled() {
|
||||
return resultSetLogger.isErrorEnabled() && super.isResultSetLogErrorEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStatementLogErrorEnabled() {
|
||||
return statementLogger.isErrorEnabled() && super.isStatementLogErrorEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void connectionLog(String message) {
|
||||
connectionLogger.debug(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void statementLog(String message) {
|
||||
statementLogger.debug(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resultSetLog(String message) {
|
||||
resultSetLogger.debug(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resultSetLogError(String message, Throwable error) {
|
||||
resultSetLogger.error(message, error);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void statementLogError(String message, Throwable error) {
|
||||
statementLogger.error(message, error);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user