• 动态修改logback日志级别


    package com.chinasofti.cloudeasy.api.web;
    
    import org.slf4j.LoggerFactory;
    import org.springframework.util.StringUtils;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    import ch.qos.logback.classic.Level;
    import ch.qos.logback.classic.LoggerContext;
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiImplicitParam;
    import io.swagger.annotations.ApiImplicitParams;
    import io.swagger.annotations.ApiOperation;
    import lombok.extern.slf4j.Slf4j;
    
    @Api(tags = "动态修改日志级别")
    @RequestMapping("api/v1/monitor")
    @RestController
    @Slf4j
    public class LogController {
    
        /**
         * 修改项目日志输出级别
         * 
         * @param allLevel 全局日志级别
         * @param singleLevel 某个类日志级别
         * @param singlePath 需要单独设置日志输出级别的类的全限定名(例:com.chinasofti.cloudeasy.api.web.LogController)
         * @return
         */
        @ApiOperation(value = "changeLogLevel")
        @GetMapping("changeLevel")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "rootLevel",
                        value = "root,全局级别:ALL,TRACE,DEBUG,INFO,WARN,ERROR,OFF", required = false),
                @ApiImplicitParam(name = "singleLevel",
                        value = "单独设置类日志级别:ALL,TRACE,DEBUG,INFO,WARN,ERROR,OFF", required = false),
                @ApiImplicitParam(name = "singlePath",
                        value = "单独类路径:com.chinasofti.cloudeasy.api.web.LogController",
                        required = false)})
        public String changeLevel(String rootLevel, String singleLevel, String singlePath) {
            LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
            log.warn("set log rootLevel:{},singleLevel:{},singlePath:{}", rootLevel, singleLevel,
                    singlePath);
            if (!StringUtils.isEmpty(rootLevel)) {
                // 设置全局日志级别
                ch.qos.logback.classic.Logger logger = loggerContext.getLogger("root");
                logger.setLevel(Level.toLevel(rootLevel));
            }
    
            if (!StringUtils.isEmpty(singleLevel)) {
                // 设置某个类日志级别-可以实现定向日志级别调整
                ch.qos.logback.classic.Logger vLogger = loggerContext.getLogger(singlePath);
                if (vLogger != null) {
                    vLogger.setLevel(Level.toLevel(singleLevel));
                }
            }
            return "success";
        }
    }
    

      

  • 相关阅读:
    HAIP异常,导致RAC节点无法启动的解决方案
    ORA-00600: internal error code, arguments: [kcbo_unlink_q_3], [0x3710B87B0]
    impdp导入报错之ORA-39126
    ORA-27102: out of memory (2019-11-29 18:30)
    ORA-00371: not enough shared pool memory
    Warning: VKTM detected a time drift.
    Cable master (POJ No.1064)
    二分查找
    结构体和类的operator<
    mybatis(基于annotation的方法知道就行了)
  • 原文地址:https://www.cnblogs.com/yaoyu1983/p/12788202.html
Copyright © 2020-2023  润新知