python3 logging日志封装

本文详细介绍了如何在Python3中使用logging模块进行日志记录,包括基本配置、日志级别设定、自定义日志格式和输出方式,旨在帮助开发者更好地实现程序的日志管理和调试。
摘要由CSDN通过智能技术生成
  •  日志脚本log_print.py

import logging
import colorlog
import os
import sys


class LogPrint(object):
    """
        from log_print import LogPrint
        import logging
        logger = LogPrint(log_file_name="runtime.log", log_level=logging.DEBUG, console_output="True", file_mode="w")
        logger.info("log info")
    """

    def __init__(self, log_file_name="runtime.log", log_level=logging.DEBUG, console_output="True", file_mode="w"):
        # 日志文件名
        self.log_file_name = log_file_name
        # 日志记录起始等级
        self.log_level = log_level
        # 窗口日志开关
        self.console_output = console_output
        # 日志记录方式,w清空写入或者a追加写入
        self.file_mode = file_mode
        # 窗口日志等级颜色字典
        self.log_color_config = {
            "DEBUG": "white",
          
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值