py
# logging object
logger = ""
def log():
"""
a log handle
"""
global logger, doc_log
import logging.handlers
logger = logging.getLogger("autons_log")
logger.setLevel(logging.DEBUG)
MAX_SIZE = 800 * 1024 * 1024
LOG_PATH = doc_log + "/autons_log.log"
fh = logging.handlers.RotatingFileHandler(LOG_PATH, maxBytes=MAX_SIZE, backupCount=8)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
def get_log():
"""
get the object of logger
"""
global logger
return logger
和 B.py
def hello():
"""
"""
import autons_nc
print autons_nc.get_log()
print type(autons_nc.get_log())
autons_nc.get_log().debug('hello')
我想在B.py中使用logger的对象,但是这种方式行不通。get_log() 的类型是“type 'str'”而不是“class 'logging.Logger'”。
那么,另一种方法可以解决吗?谢谢
顺便说一句,autons_nc.py 是 A.py