#coding: utf-8
import time '''
/*****************************************************************
Function : GetCurrFmtTime
Description : 获取当前时间
******************************************************************/
'''
def GetCurrFmtTime() :
t = time.localtime()
strtime = "%02d/%02d %02d:%02d:%02d" % (t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec)
return strtime
'''
/*****************************************************************
日志类 CLog
******************************************************************/
'''
class CLog :
def __init__(self, logFile='log.txt') :
self.DEBUG = True
self.logFile = logFile def __log__(self, *params) :
msgs = GetCurrFmtTime()
for msg in params:
if msgs != "" : msgs += " "
msgs += str(msg)
print msgs
self.__write__(msgs) def __write__(self, msgs=None) :
if len(self.logFile) > 0 :
f = open(self.logFile, 'at+')
if msgs != None : f.write(msgs)
f.write("\n")
f.close() #####################################################################
def setDebug(self, dbgFlag ) :
self.DEBUG = dbgFlag def setLogFile(self, logName ) :
self.logFile = logName ###########################################
def debug(self, *params) :
if self.DEBUG == True :
self.__log__('DBG:', *params) def info(self, *params) :
self.__log__('INF:', *params) def error(self, *params) :
self.__log__('ERR:', *params) ###########################################
def blankLine(self) :
print
self.__write__() def oneLine(self, char='=') :
line = char
for i in range(1, 50) :
line += char
print line
self.__write__(line) def titleLog(self, title) :
char = '*'
line = char
for i in range(1, 50) :
line += char msgs = '\n'
msgs += line + '\n\n'
msgs += '\t' + title + '\n\n'
msgs += line + '\n\n'
print msgs
self.__write__(msgs) #################################################################
def test() :
log = CLog()
log.titleLog('测试CLog类') log.oneLine('#') log.setDebug(False)
log.debug(2,3,4)
log.info('Hello', 'World', 100)
log.blankLine()
CLog().error('This is a test.') log.setDebug(True)
log.debug(20,30,40) log.blankLine()
log.oneLine()
######################
if __name__ == '__main__':
test()

简单实用的日志类CLog (Python版)的更多相关文章

  1. 从头认识Spring-3.8 简单的AOP日志实现(注解版)-扩展添加检查订单功能,以便记录并检測输入的參数

    这一章节我们讨论一下扩展添加检查订单功能,以便记录并检測输入的參数. 1.domain 蛋糕类: package com.raylee.my_new_spring.my_new_spring.ch03 ...

  2. 简单实用的分页类-python

    django自带的分页虽然挺好,但是就想自己弄个通用的 自己写了个分页的类,用的是python,   其他语言改下语法就能用了. #定义好类.class pagemanage: def __init_ ...

  3. php简单实用的调试工具类

    <?php /* * 调试类 */ class Common_Debug { //打开错误报告 public static function showError($debug = true) { ...

  4. C++简单实现Log日志类轻量级支持格式化输出变量

    CLog 头 代码很简单 如果需要的直接Ctrl+C  ----Ctrl+V 即可 #ifndef __CLOG__ #define __CLOG__ #include <windows.h&g ...

  5. 20181015记录一个简单的TXT日志类

    20190422添加换行以及时间记录 using System; using System.Collections.Generic; using System.IO; using System.Lin ...

  6. C#反射实现 C# 反射 判断类的延伸类型 使用代码生成工具Database2Sharp快速生成工作流模块控制器和视图代码 C# ADO.NET的SqlDataReader对象,判断是否包含指定字段 页面中添加锚点的几种方式 .net 简单实用Log4net(多个日志配置文件) C# 常用小点

    C#反射实现   一.反射概念: 1.概念: 反射,通俗的讲就是我们在只知道一个对象的内部而不了解内部结构的情况下,通过反射这个技术可以使我们明确这个对象的内部实现. 在.NET中,反射是重要的机制, ...

  7. zw版_Halcon图像交换、数据格式、以及超级简单实用的DIY全内存计算.TXT

    zw版_Halcon图像交换.数据格式.以及超级简单实用的DIY全内存计算.TXT Halcon由于效率和其他原因,内部图像采用了很多自有格式,提高运行速度,但在数据交换方面非常麻烦. 特别是基于co ...

  8. LogCook 一个简单实用的Android日志管理工具

    众所周知,日志的管理是软件系统很重要的一部分,千万不可忽略其重要性.完整的日志将会在系统维护中起着异常重要的作用,就好像磨刀不误砍柴工一样,日志就像对系统进行分析的工具,工具便捷了,对系统分析起来就能 ...

  9. python 日志类

    简介 在所有项目中必不可少的一定是日志记录系统,python为我们提供了一个比较方便的日志模块logging,通常,我们都会基于此模块编写一个日志记录类,方便将项目中的日志记录到文件中. loggin ...

随机推荐

  1. Search Insert Position--寻找插入点Given a sorted array and a target value, return the index if the target

    问题:链接 Given a sorted array and a target value, return the index if the target is found. If not, retu ...

  2. Ubuntu 12.04 安装JDK 8和Eclipse

    Ubuntu 12.04 下安装 JDK8 方法一:(缺点是安装时附加openjdk等大量程序并无法去除,长处是安装简单) $ sudo apt-get install eclipse 方法二:(长处 ...

  3. OCP-1Z0-051-题目解析-第25题

    25. You need to create a table with the following column specifications:  1. Employee ID (numeric da ...

  4. Qt新建线程的方法(有QRunnable,QThreadPool,moveToThread和QtConcurrent的例子)

    看了不少Qt线程的东西,下面总结一下Qt新建一个线程的方法. 一.继承QThread 继承QThread,这应该是最常用的方法了.我们可以通过重写虚函数void QThread::run ()实现我们 ...

  5. Denny Zhang:一辈子做一个自由职业者

    程序猿訪谈录供稿 Denny是一个旅居美国的自由职业者,这是一份让人羡慕的职业,选择这个职业意味着他已经实现某种程度上的经济自由,能够最大限度的做自己喜欢的事情,对他来说,选择自由职业作为自己终生的事 ...

  6. tcp/ip协议listen函数中backlog參数的含义

    listen函数的定义例如以下所看到的: #include <sys/socket.h> int accept(int sockfd, struct sockaddr * restrict ...

  7. linux环境设置:使ftp不输密码

    # cd ~; # vi .netrc; Add beloew words, 可以追加多个账户: machine yourservername login yourname password your ...

  8. MFC 只启动一个程序实例

    问题描述: 我们开发过程中可能会经常遇到,只启动一个程序实例.即一个程序启动之后,如果再次执行该程序,将会恢复之前打开的程序,而不是打开一个新的程序. 实现原理:利用FindWindow/FindWi ...

  9. 为什么出现Wide character in print at a14.pl line 41

    [root@wx03 ~]# cat a14.pl use Net::SMTP; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Headers; u ...

  10. POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)

    Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Des ...