ecology_maven/aiyh/utils/zwl/common/logging/Log4JLogger.java

90 lines
2.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package aiyh.utils.zwl.common.logging;
/**
* 写日志log4j
* @date 2020-03-10
* @version 1.0
*/
public class Log4JLogger implements Logger {
private org.apache.log4j.Logger log;
//类名
private String classname;
@Override
public String getClassname() {
return classname;
}
@Override
public void setClassname(String classname) {
this.classname = classname;
}
@Override
public boolean isDebugEnabled() {
return log.isDebugEnabled();
}
@Override
public boolean isInfoEnabled() {
return log.isInfoEnabled();
}
@Override
public void debug(Object message) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.debug(classname+"."+method+"() - "+message);
}
@Override
public void debug(Object message, Throwable exception) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.debug(classname+"."+method+"() - "+message, exception);
}
@Override
public void info(Object message) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.info(classname+"."+method+"() - "+message);
}
@Override
public void info(Object message, Throwable exception) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.info(classname+"."+method+"() - "+message, exception);
}
@Override
public void warn(Object message) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.warn(classname+"."+method+"() - "+message);
}
@Override
public void warn(Object message, Throwable exception) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.warn(classname+"."+method+"() - "+message, exception);
}
@Override
public void error(Object message) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.error(classname+"."+method+"() - "+message);
}
@Override
public void error(Object message, Throwable exception) {
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
log.error(classname+"."+method+"() - "+message, exception);
}
@Override
public void init(String name) {
if("".equals(name)) {
name = "cuslog";
}
log = org.apache.log4j.Logger.getLogger(name);
}
}