简体   繁体   English

在日志中打印Spring Schedule信息

[英]Print Spring Schedule information in logs

I am using Spring @Schedule annotation to schedule a job. 我正在使用Spring @Schedule批注计划工作。 Is there any way to print when @Schdeule will start the job? @Schdeule启动作业时,有什么方法可以打印? I had enable TRACE level logging however nothing is printed in logs related to schedule. 我启用了TRACE级别的日志记录,但是在与计划相关的日志中未打印任何内容。 Basically I am looking after how much time my schedule will start - 基本上,我要照顾我的时间表开始多少时间-

@Service
public class Listener{

    @Log
    private Logger logger;



    @Scheduled(cron = "0 12 16 * * *")
    public void closing() throws Exception {
        //do work here

    }
}

Thanks 谢谢

A simple way to achieve that can be by adding a log in the begin of your method this one will write the date also : 一种简单的实现方法是在方法的开头添加一个日志,该日志还将写出日期:

@Service
public class Listener{

    @Log
    private Logger logger;



    @Scheduled(cron = "0 12 16 * * *")
    public void closing() throws Exception {
        logger.info("start of the method");
        //do work here

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM