lib_xml.py 的模块:
import conf_store
def hello():
print conf_store.logger
conf_store.logger.debug('why')
print 'where'
conf_store.py 的模块:
#! /usr/bin/python
import os, subprocess, logging, time, shutil, fcntl
import lib_xml
def log():
"""
a log handle
"""
import logging.handlers
global logger
LOG_PATH = "/opt/conf_store.log"
logger = logging.getLogger('conf_store')
logger.setLevel(logging.DEBUG)
ch = logging.handlers.WatchedFileHandler(LOG_PATH)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
if __name__ == "__main__":
log()
while(True):
lib_xml.hello()
logger.debug('what')
如何logger
在 lib_xml.py 和 conf_store.py 之间共享对象?