Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用FileHandler-Logging python将变量放入log_config.yaml_Python_Windows_Selenium_Logging_Yaml - Fatal编程技术网

如何使用FileHandler-Logging python将变量放入log_config.yaml

如何使用FileHandler-Logging python将变量放入log_config.yaml,python,windows,selenium,logging,yaml,Python,Windows,Selenium,Logging,Yaml,我有一个用于登录python的文件配置(.yaml),其中包含一个在文件中写入日志的文件处理程序。 当我放置绝对路径时,它工作,但当我放置包含路径的变量时,它不工作 #my_program/resources/log_config.yaml handlers: file: class: logging.handlers.TimedRotatingFileHandler level: DEBUG formatter: standard

我有一个用于登录python的文件配置(.yaml),其中包含一个在文件中写入日志的文件处理程序。 当我放置绝对路径时,它工作,但当我放置包含路径的变量时,它不工作

#my_program/resources/log_config.yaml

handlers:
    file:
        class: logging.handlers.TimedRotatingFileHandler
        level: DEBUG
        formatter: standard
        filename: "C:/workspace/my_program/results/errors.log"
        when: midnight
        encoding: utf8
我试过:

filename: "../results/errors.log"
我试着把一个可变的环境

filename: " {{$PROJECT_HOME}}/results/errors.log"
输出:

ValueError:无法配置处理程序“文件”

UnboundLocalError: local variable 'logger' referenced before assignment
我需要将路径放在包含我使用的所有路径的其他文件设置中 或者至少使用包含路径的变量ENV


如何将动态变量放入yaml文件中?

您可以自己创建子类
TimedRotatingFileHandler
并实现目标路径构造,例如通过读取env VAR等。或者您可以使用自己的标记扩展yaml语法,如所述(搜索“构造函数、重输入、解析程序”部分)。您可以子类化
TimedRotatingFileHandler
并自己实现目标路径构造,例如通过读取env VAR等。或者您可以使用自己的标记扩展YAML语法,如所述(搜索“构造函数、重表示项、解析器”部分)。