package com.engine.htsc.payment.log;

/**
 * 写日志（log4j）
 */
public class Log4JLogger implements PaymentLogger {

    private org.apache.log4j.Logger log;
    //类名
    private String classname;

    public String getClassname() {
        return classname;
    }

    public void setClassname(String classname) {
        this.classname = classname;
    }

    public boolean isDebugEnabled() {
        return log.isDebugEnabled();
    }

    public boolean isInfoEnabled() {
        return log.isInfoEnabled();
    }

    public void debug(Object message) {
        String method = Thread.currentThread().getStackTrace()[2].getMethodName();
        log.debug(classname + "." + method + "() - " + message);
    }

    public void debug(Object message, Throwable exception) {
        String method = Thread.currentThread().getStackTrace()[2].getMethodName();
        log.debug(classname + "." + method + "() - " + message, exception);
    }

    public void info(Object message) {
        String method = Thread.currentThread().getStackTrace()[2].getMethodName();
        log.info(classname + "." + method + "() - " + message);
    }

    public void info(Object message, Throwable exception) {
        String method = Thread.currentThread().getStackTrace()[2].getMethodName();
        log.info(classname + "." + method + "() - " + message, exception);
    }

    public void warn(Object message) {
        //通过线程获取当前调用的方法名
        String method = Thread.currentThread().getStackTrace()[2].getMethodName();
        log.warn(classname + "." + method + "() - " + message);
    }

    public void warn(Object message, Throwable exception) {
        String method = Thread.currentThread().getStackTrace()[2].getMethodName();
        log.warn(classname + "." + method + "() - " + message, exception);
    }

    public void error(Object message) {
        String method = Thread.currentThread().getStackTrace()[2].getMethodName();
        log.error(classname + "." + method + "() - " + message);
    }

    public void error(Object message, Throwable exception) {
        String method = Thread.currentThread().getStackTrace()[2].getMethodName();
        log.error(classname + "." + method + "() - " + message, exception);
    }

    public void init(String name) {
        if ("".equals(name))
            name = "payment";
        log = org.apache.log4j.Logger.getLogger(name);
    }
}
