Any alternative for logging.config.dictConfig(config) ? I can't bypass SonarQube quality gate due to the following SonarQube error : 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 file of this code:
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]
I wanna know how to solve this issue or find alternatives for it
This rule is deprecated now and will be deleted. https://rules.sonarsource.com/python/RSPEC-4792/