• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python简单日志处理类分享

Python简单日志处理类分享

作者:junjie 字体:[增加 减小] 来源:互联网

junjie 通过本文主要向大家介绍了python 打印日志,python 3日志,python web日志分析,python输出日志,python处理日志等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

简单的一个python日志处理类
#/usr/bin/python
#coding=utf-8

import time,types

class logsys:

    def __init__(self, project, logfilename = 'sys_log.txt'):
        self.project = project
        self.logfilename = logfilename

    def get_log_time(self):
        return time.strftime("%Y-%m-%d %X", time.localtime())

    def write2file(self, *formart):
        s = self.formart_string(*formart)
        if s:
            encoding = 'utf8'
            out = open(self.logfilename, 'a+')
            out.write(s + "\n")
            out.close()
        else:
            pass

    def formart_string(self, *formart):
        string = ''
        encoding = 'utf8'
        for str in formart:
            if not type(str) in [types.UnicodeType, types.StringTypes, types.StringType]:
                s = repr(str)
            else:
                s = str
            if type(s) == type(u''):
                string += s.encode(encoding) + "\t"
            else:
                string += s + "\t"
        return string

    def w(self,notice,*formart):
        self.write2file(self.get_log_time(), '[' + notice + ']', self.project, *formart)

</div>

</div>

您可能想查找下面的文章:

  • python日志记录模块实例及改进
  • Python统计日志中每个IP出现次数的方法
  • python统计日志ip访问数的方法
  • python写日志封装类实例
  • Python简单日志处理类分享
  • python 从远程服务器下载日志文件的程序

相关文章

  • Python多线程学习资料
  • Python中的字典遍历备忘
  • python list语法学习(带例子)
  • 简单的Apache+FastCGI+Django配置指南
  • python使用PyGame播放Midi和Mp3文件的方法
  • python检测远程服务器tcp端口的方法
  • python操作ie登陆土豆网的方法
  • Python中的anydbm模版和shelve模版使用指南
  • python之文件的读写和文件目录以及文件夹的操作实现代码
  • python中的对象拷贝示例 python引用传递

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python操作列表的常用方法分享
    • python读取word文档的方法
    • Python使用爬虫猜密码
    • python函数返回多个值的示例方法
    • 在Python的web框架中中编写日志列表的教程
    • python解析xml文件实例分享
    • python使用calendar输出指定年份全年日历的方法
    • Python多进程机制实例详解
    • Python bsddb模块操作Berkeley DB数据库介绍
    • SQLite3中文编码 Python的实现

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有