springboot2.0.3 configuration log

The reason: SpringBoot default log when using slf4j, the introduction of other frameworks, just need to rely on this framework logging framework excluded;

And today I want to introduce log4j time, pom file has an error, the display can not find the log4j jar package, should be springboot version 2.0.3 of reasons;

In this no longer continue to introduce, instead of using slf4j log SpringBoot used, there is a chance retest efficiency log4j slf4j both logs and contrast.

A, application.yml configuration log printing level, the default is info (also choose different directories):

# slf4j log configuration 
logging: 
  # Configure Level 
  Level: 
    # subcontracting configuration level, that is different directories can use different levels 
    com.sblueice.controller: debug

Two, logback.xml in all configurations:

  Configure the print path to the file (one day a, for 30 days):

    <! - development, test environment -> 
    <springProfile name = "dev, the Test"> 
        <! - defined log storage path, not a relative path configuration -> 
        <Property name = "FILE_PATH" value = "E: /temp0918/SpringBoot-log/cccf.%d{yyyy-MM-dd}.%i.log "/> 
    </ springProfile> 

 configuration of the printing log sql:
 <logger name="com.sblueice.mapper.UserMapper" level="DEBUG" />
<? Xml Version = "1.0" encoding = "UTF-8" ?> 
< The Configuration > 
 
    <-! Formatted output:% date represents the date,% thread indicates that the thread name,% - 5level: Level 5 characters displayed from left width% msg: log messages,% n newline -> 
    < Property name = "LOG_PATTERN" 
              value = "{% DATE HH: mm: ss.SSS} [Thread%]% {36} Logger -5level% -% % n-MSG "  /> 
 
    <-! development, test environment -> 
    < springProfile name =" dev, test " > 
        <-! custom log storage path, not the relative path configuration -> 
        < Property name =" the FILE_PATH " value =" E:/temp0918/SpringBoot-log/cccf.%d{yyyy-MM-dd}.%i.log" />
    </ SpringProfile > 
    
    <-! Production Environment -> 
    < springProfile name = "Pro" > 
        <-! Custom log storage path, not the relative path configuration -> 
        < Property name = "the FILE_PATH" value = "/ User /lib/cccf/logs/cccf.%d{yyyy-MM-dd}.%i.log "  /> 
    </ springProfile > 
 
    <-! console output log -> 
    < the appender name =" console " class = "ch.qos.logback.core.ConsoleAppender" > 
        < Encoder > 
            <!- according to the above configuration LOG_PATTERN print log -> 
            <pattern > $ {LOG_PATTERN} </ pattern > 
        </ Encoder > 
    </ the appender > 
 
    <-! generates a daily log file, the log file for 30 days. rollingFile segmentation file is used -> 
    < the appender name = "rollingFile" 
        class = "ch.qos.logback.core.rolling.RollingFileAppender" > 
        < rollingPolicy class = "ch.qos.logback.core.rolling.TimeBasedRollingPolicy " > 
            < fileNamePattern > 
                $ {} the FILE_PATH 
            </ fileNamePattern > 
            <-! Keep 30 Days'
            <maxHistory>30</maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- 日志文件的最大大小 -->
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
 
        <encoder>
            <pattern>${LOG_PATTERN}</pattern>
        </encoder>
    </appender>
    <!-- project default level -->
    <logger name="com.hiynn.cccf" level="INFO" />
 
    <!-- 日志输出级别 -->
    <root level="INFO">
        <appender-ref ref="console" />
        <appender-ref ref="rollingFile" />
    </root>

    <!--myibatis log configure-->
    <logger name="com.sblueice.mapper.UserMapper" level="DEBUG" />
</configuration>

Three, controller layer prints log (Java how no coloring ....)

package com.sblueice.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sblueice.services.UserService;

/**
 * 
 * @author shaoz
 * @Date: 2019/10/09
 * 
 */

@Controller
public class{The UserController 
    
    
    Logger Logger = LoggerFactory.getLogger (getClass ()); 
    
    / ** 
     * 
    * @Title: TESTLOG 
    * @Description: the TODO (springboot own log printing test) 
    * @param : @return 
    * @return : String 
    * @ throws 
     * / 
    @RequestMapping ( "/ TESTLOG" ) 
    @ResponseBody 
    public String TESTLOG () { 
        
            // level from low to high trace <Debug <info <the warn <error 
            logger.trace ( "this is a trace log ..." ) ; 
            logger.debug ( "this is a debug log ..." );
             //SpringBoot default level is info, just above the level of output and info log 
            logger.info ( "This is an info log ..." ); 
            logger.warn ( "This is a warn log ..." ); 
            logger.error ( "this is an error log ..." ); 
            String str = "https://www.cnblogs.com/steveshao/" ; 
            logger.info ( "====== Welcome to the legless bird blog: } {\ n-" , STR); 
         
            return  null ; 
    } 

}
    

And that 's SpringBoot printing process logs, also draws a lot of people things, the current draw can not find the link, if some students think I'm your text excerpt, please contact me to add on to your description link Kazakhstan.

 

Guess you like

Origin www.cnblogs.com/steveshao/p/11649537.html