Sonarqube错误确保此记录器的配置是安全的

问题描述 投票:0回答:1

loggging.config.dictconfig(config)的任何替代方案?由于以下声音错误,我无法绕过Sonarqube质量门:

logging.config.dictConfig(config) : Make sure that this logger's configuration is safe.


def setup_logging(log_file_path):

    with open('logging_config.yaml', 'r') as file:
        config = yaml.safe_load(file)
    
    # Update the filename in the config
    config['handlers']['file']['filename'] = log_file_path
    
    logging.config.dictConfig(config)
    logger = logging.getLogger('logger')
    logger.info("\n")
    logger.info("Log File Created")
    return logger

此代码的yaml文件:

version: 1 disable_existing_loggers: false formatters: detailed: format: '%(asctime)s | %(levelname)s %(process).5d | %(lineno)d:%(module)s:%(funcName)s -- %(message)s' datefmt: '%Y-%m-%d %H:%M:%S' handlers: file: class: logging.handlers.RotatingFileHandler level: INFO formatter: detailed filename: "app.log" mode: a maxBytes: 1048576 # 1 MB (1 * 1024 * 1024) backupCount: 5 # Keep 5 backup files loggers: my_logger: level: INFO handlers: [file] propagate: no root: level: INFO handlers: [file]
我想知道如何解决这个问题或为IT找到替代方案

python logging sonarqube sonarqube-scan
1个回答
0
投票
该规则现在被弃用,将被删除。

https://rules.sonarsource.com/python/rspec-4792/

© www.soinside.com 2019 - 2024. All rights reserved.