我在使用我的应用程序中的日志记录模块时遇到问题。我在Eclipse上使用我的MacBook Pro上的LDT Python(Py 2.7)界面(而不是Pydev)。日志记录模块通过Eclipse工作;但是,当我将应用程序转移到RHEL5 2.7时,日志似乎根本不起作用。它不会抛出任何异常,它只是不记录任何东西到控制台或文件(它会创建文件)。Python日志记录模块在Mac上登录,但不是在Linux上登录
代码:
# Initialize logging
log = logging.getLogger('pepPrep')
# Log to stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# Log to file
logname = 'pepPrep.' + datetime.datetime.now().strftime("%Y%m%d_%H:%M") + '.log'
filelog = logging.FileHandler(logname)
filelog.setLevel(logging.DEBUG)
# set a format
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
# tell the handler to use this format
console.setFormatter(formatter)
filelog.setFormatter(formatter)
# add the handler to the root logger
log.addHandler(console)
log.addHandler(filelog)
log.INFO('This is a test')
log.DEBUG('This is a test2')
上我怎样才能使这项工作的任何指针?
您是否正确关闭日志? – ismail 2011-01-24 15:20:30