package test
import java.io.IOException
import org.apache.log4j.FileAppender
import org.apache.log4j.Level
import org.apache.log4j.Logger
import org.apache.log4j.SimpleLayout
object LoggerUtil {
def getLogger(clazz: Class[_], fileName: String): Logger = {
val logger = Logger.getLogger(clazz)
logger.setLevel(Level.INFO)
//设置是否继承父Logger,默认会有标准输出,false不会标准输出
logger.setAdditivity(false)
try {
logger.addAppender(new FileAppender(new SimpleLayout(), "/tmp/prop_logs/" + fileName + ".sql"))
} catch {
case e1: IOException => e1.printStackTrace()
}
return logger
}
}
logger.setAdditivity(false)可以关闭标准输出