From 1a3f0ea3023b24d1eaf27b10cd455e354a4d9955 Mon Sep 17 00:00:00 2001 From: EarthmanT Date: Wed, 27 Oct 2021 10:40:05 -0400 Subject: [PATCH] get_logger uses root directory file No automation system should have write access to this file. https://florimond.dev/en/posts/2018/08/python-mutable-defaults-are-the-source-of-all-evil/ --- pyvcloud/vcd/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyvcloud/vcd/client.py b/pyvcloud/vcd/client.py index 23d0c409..9c84c7fc 100644 --- a/pyvcloud/vcd/client.py +++ b/pyvcloud/vcd/client.py @@ -23,6 +23,7 @@ import sys import time import urllib +from tempfile import NamedTemporaryFile from lxml import etree from lxml import objectify @@ -2184,7 +2185,7 @@ def create_element(node_name, value=None): return element -def get_logger(file_name="vcd_sdk.log", +def get_logger(file_name=None, log_level=logging.DEBUG, max_bytes=10000000, backup_count=10): @@ -2212,6 +2213,9 @@ def get_logger(file_name="vcd_sdk.log", :return: Logger with rotating file handler. :type: LOGGER """ + if not file_name: + tf_obj = NamedTemporaryFile(delete=False) + file_name = tf_obj.name LOGGER = logging.getLogger(file_name) logHandler = handlers.RotatingFileHandler( filename=file_name, maxBytes=max_bytes, backupCount=backup_count)