通过java代码给log4j指定appender
工具代码
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.LogManager;
import org.apache.log4j.PatternLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LogUtil {
public static final Logger LOGGER = LoggerFactory.getLogger(LogUtil.class);
static {
org.apache.log4j.Logger logger = LogManager.getLogger(LOGGER.getName());
ConsoleAppender consoleAppender = new ConsoleAppender(new PatternLayout("%d [%t] %-5p [%c] - %m%n"));
logger.addAppender(consoleAppender);
}
}
使用
LogUtil.LOGGER.info("hello!");
如果你觉得这篇文章对你有帮助或者使你有所启发,请点击右下角的推荐按钮,谢谢,:)