zoukankan      html  css  js  c++  java
  • python3 logging 日志记录模块

    #coding:utf-8

    import logging
    logging.basicConfig(filename='log1.log',
    format='%(asctime)s -%(name)s-%(levelname)s-%(module)s:%(message)s',
    datefmt='%Y-%m-%d %H:%M:%S %p',
    level=logging.DEBUG)

    while True:
    option = input("input a digit:")
    if option.isdigit():
    print("hehe",option)
    logging.info('option correct')
    else:
    logging.error("Must input a digit!")




    # logging.debug('有bug')
    # logging.info('有新的信息')
    # logging.warning('警告信息')
    # logging.error('错误信息')
    # logging.critical('紧急错误信息')
    # logging.log(10,'log')



    #coding:utf-8
    import logging

    logger = logging.getLogger("simple_example")
    logger.setLevel(logging.DEBUG)

    #输出到屏幕
    ch = logging.StreamHandler()
    ch.setLevel(logging.WARNING)
    #输出到文件
    fh = logging.FileHandler("log2.log")
    fh.setLevel(logging.INFO)
    #设置日志格式
    fomatter = logging.Formatter('%(asctime)s -%(name)s-%(levelname)s-%(module)s:%(message)s')
    ch.setFormatter(fomatter)
    fh.setFormatter(fomatter)
    logger.addHandler(ch)
    logger.addHandler(fh)

    logger.debug("debug message")
    logger.info("info message")
    logger.warning("warning message")
    logger.error("error message")
    logger.critical("critical message")






  • 相关阅读:
    第一篇代码 嗨翻C语言 21点扑克
    Windows7 sp1 64位下安装配置eclipse+jdk+CDT+minGW
    MinGW-64 安装
    Windows Live Writer配置步骤
    Css 居中
    c++ 常量成员函数
    c/c++ 引用计数
    C++ 《STL源码剖析》学习-vector
    C/C++ 有符号数和无符号数
    cocos2d 内存管理机制
  • 原文地址:https://www.cnblogs.com/Devopser/p/6366975.html
Copyright © 2011-2022 走看看