- 裝飾器
import logging
def use_logging_with_multi_param(fun):
def wrapper(*args):
logging.warning('[%s is running]' % fun.__name__)
return fun(args)
return wrapper
@use_logging_with_multi_param
def test(expect="hello"):
print(expect)
test("hello world")
- 打印報錯UnicodeEncodeError
修改logging.FileHandler中的encode爲utf-8
class FileHandler(StreamHandler):
"""
A handler class which writes formatted logging records to disk files.
"""
def __init__(self, filename, mode='a', encoding="utf-8", delay=False):