一、添加maven依赖
org.apache.logging.log4j log4j-api ${log4j.version} org.apache.logging.log4j log4j-core ${log4j.version}
二、log4j2.xml配置文件
%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%level] %logger{36} - %msg%n log4j2learn.log
三、测试代码
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;/** * @author : zhangyanqing * @time : 2017/12/9 * @desc : 输出日志到文件 */public class FileLoggerTest { public static final Logger LOGGER = LogManager.getLogger("AsyncFileLogger"); public static void main(String[] args){ LOGGER.trace("trace level"); LOGGER.debug("debug level"); LOGGER.info("info level"); LOGGER.warn("warn level"); LOGGER.error("error level"); LOGGER.fatal("fatal level"); }}