zoukankan      html  css  js  c++  java
  • logging 至 file 和 cli 附简短debug设置

    多数情况下(呃,我是说调参党的话)需要将logging 的输出同时写到 文件 和命令行中,但这个接口似乎有些繁,每次都要艰难地找。在万能的stack overflow上 找到些线索,记在这里:

    import logging
    outputPath='./'
    logging.basicConfig(level=logging.INFO,
                filename=outputPath+'-training.log',
                        format='[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s'
                )
    console = logging.StreamHandler()
    logging.getLogger('').addHandler(console)
    formatter = logging.Formatter('[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s')
    console.setFormatter(formatter)
    
    logging.info('Hello World!')
    #test ok!
    

    另外 ,

    1. 在MXNet中 glog和logging 似乎有些冲突,最好用logging ;
    2. logging 的配置要放在最前面,否则容易失效。

    debug设置

    debug设置主要是直接输出到屏幕上,设置叫简短,但还是令人有些烦:

    import logging
    logging.basicConfig(level=logging.DEBUG,format='%(levelname)s: %(asctime)s %(filename)s [line: %(lineno)d]  %(message)s')
    logging.debug('This is debug print')
    
  • 相关阅读:
    好了伤疤,忘了疼,我又崴脚了
    征途 --从 5公里 前端 开始
    MVC 感触
    2公里
    又受伤了打篮球
    Unity Lighting,lighting map,probes
    UnityPostProcessing笔记
    unity HDRP和URP
    blender2.8 import fbx armature setting
    U3D资源加载框架迭代笔记
  • 原文地址:https://www.cnblogs.com/chenyliang/p/6780377.html
Copyright © 2011-2022 走看看