I am trying to config the logger using logging.conf file but I am getting error, In Code I am trying to replace the file path in conf file with dynamic path includes timestamp folder Following is my code
python module to configure the log -
class LogHandler: logger = None def __init__(self,file_path): conf_path = os.path.dirname(os.getcwd())+"\\config\\log_config.conf" #Setting the log file path to configuration file with open(conf_path,'r') as file: content = file.readlines() file_path = file_path.replace("\\", "\\\\") print(file_path) for line_no in range(len(content)): if re.search("args=\('.*',", content[line_no]): content[line_no] = "args=('" + file_path + "','a')\n" break file.close() with open(conf_path,'w') as file: file.write(''.join(content)) file.close() logging.config.fileConfig(conf_path) LogHandler.logger = logging.getLogger("root") LogHandler.logger.info("Testing") @staticmethod def getLogger(): return LogHandler.logger logging.conf module for configuration -
[loggers] keys=root [handlers] keys=consoleHandler [formatters] keys=sampleFormatter [logger_root] level=DEBUG handlers=consoleHandler [handler_consoleHandler] class=StreamHandler level=DEBUG formatter=sampleFormatter args=('C:\\Users\\vipin\\PycharmProjects\\PythonBehaveFramework\\output\\201912100840\\output.log','a') [formatter_sampleFormatter] format=%(asctime)s : %(lineno)s - %(funcName)s - %(levelname)s - %(message)s Error -
Traceback (most recent call last): File "C:/Users/vipin/PycharmProjects/PythonBehaveFramework/Features/test.py", line 8, in <module> LogHandler.getInstance("C:\\Users\\vipin\\PycharmProjects\\PythonBehaveFramework\\output\\output.log") File "C:\Users\vipin\PycharmProjects\PythonBehaveFramework\src\framework\LogHandler.py", line 28, in getInstance LogHandler(filename) File "C:\Users\vipin\PycharmProjects\PythonBehaveFramework\src\framework\LogHandler.py", line 50, in __init__ logging.config.fileConfig(conf_path) File "C:\Users\vipin\AppData\Local\Programs\Python\Python36-32\lib\logging\config.py", line 84, in fileConfig handlers = _install_handlers(cp, formatters) File "C:\Users\vipin\AppData\Local\Programs\Python\Python36-32\lib\logging\config.py", line 148, in _install_handlers h = klass(*args) TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given