日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 程序停止打印日志_Python日志打印

發(fā)布時間:2025/3/11 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 程序停止打印日志_Python日志打印 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

簡單示例

import sys

import ctypes

import logging

import logging.handlers

reload(sys)

sys.setdefaultencoding('utf-8')

LOG_FILE = 'test_log'

logging.basicConfig(

filename = LOG_FILE,

format = '%(asctime)s - %(levelname)s -%(process)d- %(filename)s:%(funcName)s:%(lineno)d - %(message)s',

level = logging.DEBUG)

logging.handlers.TimedRotatingFileHandler(LOG_FILE, when='W0', backupCount=5)

logger = logging.getLogger(__name__)

if __name__ == "__main__":

logger.info("hello info")

logger.error("hello info")

logger.warn("hello info")

在filename的位置 可以填 相對位置 ,也可以填絕對位置 。

這個format = '%(asctime)s - %(levelname)s -%(process)d- %(filename)s:%(funcName)s:%(lineno)d - %(message)s ?信息比較全,其他還有

%(levelno)s: 打印日志級別的數(shù)值 %(levelname)s: 打印日志級別名稱 %(pathname)s: 打印當前執(zhí)行程序的路徑,其實就是sys.argv[0] %(filename)s: 打印當前執(zhí)行程序名 %(funcName)s: 打印日志的當前函數(shù) %(lineno)d: 打印日志的當前行號 %(asctime)s: 打印日志的時間 %(thread)d: 打印線程ID %(threadName)s: 打印線程名稱 %(process)d: 打印進程ID %(message)s: 打印日志信息

用 info和 error 不同的方法打印日志,便于快速找到出錯情況。

總結

以上是生活随笔為你收集整理的python 程序停止打印日志_Python日志打印的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。