小编ana*_*tta的帖子

logging.debug 的多个参数

蟒蛇 2.7

我目前使用多行代码进行日志记录,如下所示:

timestr = time.strftime("%Y%m%d_%H%M%S")
print timestr
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M',
                    filename='D://my_code_3/logging/'+timestr+'_XFR.log',
                    filemode='w')
#define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)
#set a format which is simpler for console use
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
#tell the handler to use this format
console.setFormatter(formatter)
#add the handler to the root logger
logging.getLogger('').addHandler(console)

name = raw_input("Please enter your name.")
print 'Hi ', name, 'Please go ahead and transfer files - …
Run Code Online (Sandbox Code Playgroud)

string logging python-2.7

3
推荐指数
1
解决办法
4960
查看次数

标签 统计

logging ×1

python-2.7 ×1

string ×1