zoukankan      html  css  js  c++  java
  • Python同时向控制台和文件输出日志logging的方法 Python logging模块详解

     Python同时向控制台和文件输出日志logging的方法http://www.jb51.net/article/66756.htm

     1 #-*- coding:utf-8 -*-
     2 import logging
     3 # 配置日志信息
     4 logging.basicConfig(level=logging.DEBUG,
     5           format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
     6           datefmt='%m-%d %H:%M',
     7           filename='myapp.log',
     8           filemode='w')
     9 # 定义一个Handler打印INFO及以上级别的日志到sys.stderr
    10 console = logging.StreamHandler()
    11 console.setLevel(logging.INFO)
    12 # 设置日志打印格式
    13 formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
    14 console.setFormatter(formatter)
    15 # 将定义好的console日志handler添加到root logger
    16 logging.getLogger('').addHandler(console)
    17 logging.info('Jackdaws love my big sphinx of quartz.')
    18 logger1 = logging.getLogger('myapp.area1')
    19 logger2 = logging.getLogger('myapp.area2')
    20 logger1.debug('Quick zephyrs blow, vexing daft Jim.')
    21 logger1.info('How quickly daft jumping zebras vex.')
    22 logger2.warning('Jail zesty vixen who grabbed pay from quack.')
    23 logger2.error('The five boxing wizards jump quickly.')

    http://blog.csdn.net/zyz511919766/article/details/25136485

  • 相关阅读:
    今天面试一些程序员(新,老)手的体会
    UVA 10635 Prince and Princess
    poj 2240 Arbitrage
    poj 2253 Frogger
    poj 2485 Highways
    UVA 11258 String Partition
    UVA 11151 Longest Palindrome
    poj 1125 Stockbroker Grapevine
    poj 1789 Truck History
    poj 3259 Wormholes
  • 原文地址:https://www.cnblogs.com/pyfreshman/p/5145962.html
Copyright © 2011-2022 走看看