logback
简介
- logback是springboot自带的日志服务,不需要单独导入依赖。
具体代码
application.yml 配置
logging:
level:
com.st.controller.StaffController: INFO
com.st.service.impl.StaffService: DEBUG
path: E:\workspace-idel\log
file: E:\workspace-idel\log\bootDemo.log
pattern:
console: "%d - %msg%n"
mybatis:
mapper-locations: classpath:mybatis/*Mapper.xml
type-aliases-package: com.st.model
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
使用示例
package com.st.controller;
import com.st.service.IStaffService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("staff")
public class StaffController {
private Logger logger = LoggerFactory.getLogger(StaffController.class);
@RequestMapping("home")
public String toHome(){
logger.info("---info:跳转到主页---");
return "home";
}
}
定时任务
package com.st.job;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.Date;
@Configuration
@EnableScheduling
public class MyJob {
@Scheduled(cron = "0/5 * * * * ?")
public void task(){
System.out.println(new Date());
}
}