非web服务配置log4j

来源:互联网 发布:nginx proxy ssl 编辑:程序博客网 时间:2024/06/06 11:36

N次出现本地debug没有log了。记录一下

主函数代码

public class Main {    private static Log logger = LogFactory.getLog(Main.class);    public static void main(String[] args) {        final ApplicationContext context = new ClassPathXmlApplicationContext("classpath:application-context.xml");        logger.trace("Loaded application-context.xml");        final Server server = SpringContextUtil.getBean("server", Server.class);        // 钩子函数,保证优雅退出        Runtime.getRuntime().addShutdownHook(new Thread() {            public void run() {                logger.info("Serveris stopping...");                server.stop();                SpringContextUtil.close();                logger.info("Server is stoped");            }        });        logger.info("Server is starting...");        server.start();    }}

配置

-Dconfig.file.path=config-Dconfig.file=config/setting.properties-Dlog4j.configuration=file:config/log4j.properties-Dconfig.quartz.file=config/quartz.properties

idea配置

这里写图片描述

需要注意的是 Use classpath of module不要选错了!以这个作为项目的root的