springboot-Log

1 spring boot-Log 日志  pom.xml



    org.springframework.boot
    spring-boot-starter
    
        
            org.springframework.boot
            spring-boot-starter-logging
        
    




    org.springframework.boot
    spring-boot-starter-log4j2

2日志代码 测试

package com.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


@Controller
public class User {

    private static final Logger logger;

    static {
        logger = LogManager.getLogger(User.class);
    }


    @RequestMapping("/user")
    @ResponseBody

    public  String ShowHelloWorld()
    {
        logger.error("开始");
        return  "HelloWorld";

    }

}

测试结果 :2019-02-23 16:43:05.787 ERROR 768 --- [nio-8080-exec-1] c.e.d.User                               : 开始

 

你可能感兴趣的:(SpringBoot)