springboot默认的日志管理工具logback的配置

1.首先创建xxx-spring.xml(必须是以spring结尾)

springboot默认的日志管理工具logback的配置_第1张图片

2.logback-spring.xml的内容编辑



    

    
    
        
        
            UTF-8
            %d [%t] %-5level %logger{36}.%M\(%file:%line\) - %msg%n
        
    

    
        
        
            
            ERROR
            
            DENY
            
            ACCEPT
        
        ${logback.logDir}/info.log
        
        
            
            ${logback.logDir}/info.%d{yyyy-MM-dd}.%i.log.gz
            
            100MB
            
            30
            
            
        
        
        
            UTF-8
            %d [%t] %-5level %logger{36}.%M\(%file:%line\) - %msg%n
        
    

    
        
        
            ERROR
        
        
        ${logback.logDir}/error.log
        
        
            
            ${logback.logDir}/error.%d{yyyy-MM-dd}.%i.log.gz
            
            100MB
            
            30
            
            
        
        
        
            UTF-8
            %d [%t] %-5level %logger{36}.%M\(%file:%line\) - %msg%n
        
    

    
        
        
        
            ERROR
        
    

    
        
        
        
        
    

 

3.在要使用log的类上面加入注解@Slf4j就直接可以用log来使用(eg:)

@Slf4j
@Service
public class AccountService {

public UserLoginResponseVO loginByWechat(String accessCode, DeviceTypeEnum deviceType, String appChannel,
        String appVersion, String deviceId) {
    UserInfoPO userInfoPO = WechatLoginService.register(accessCode);
    if (userInfoPO == null) {
        log.error("Failed to register by wechat");
        throw new ServiceException(ResultEnum.FAILED_TO_CREATE_USER);
    }

    return login(userInfoPO, deviceType, appChannel, appVersion, UserRegisterTypeEnum.WECHAT, deviceId);
    }
}

 

 

 

你可能感兴趣的:(springboot,java资源)