小编xki*_*ill的帖子

如何使用不同的类和导入动态地使用Python日志记录来更改文件句柄

我无法执行即时记录文件手柄更改.

例如,我有3个班级

one.py

import logging
class One():
    def __init__(self,txt="?"):
        logging.debug("Hey, I'm the class One and I say: %s" % txt)
Run Code Online (Sandbox Code Playgroud)

two.py

import logging
class Two():
    def __init__(self,txt="?"):
        logging.debug("Hey, I'm the class Two and I say: %s" % txt)
Run Code Online (Sandbox Code Playgroud)

config.py

import logging
class Config():
    def __init__(self,logfile=None):
        logging.debug("Reading config")
        self.logfile(logfile)
Run Code Online (Sandbox Code Playgroud)

myapp

from one import One
from two import Two
from config import Config
import logging

#Set default logging
logging.basicConfig( 
    level=logging.getLevelName(DEBUG), 
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    filename=None
)

logging.info("Starting with stdout") …
Run Code Online (Sandbox Code Playgroud)

python configuration logging

42
推荐指数
4
解决办法
3万
查看次数

标签 统计

configuration ×1

logging ×1

python ×1