简单实用的日志类CLog (Python版)
#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) :
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版)的更多相关文章
- 从头认识Spring-3.8 简单的AOP日志实现(注解版)-扩展添加检查订单功能,以便记录并检測输入的參数
这一章节我们讨论一下扩展添加检查订单功能,以便记录并检測输入的參数. 1.domain 蛋糕类: package com.raylee.my_new_spring.my_new_spring.ch03 ...
- 简单实用的分页类-python
django自带的分页虽然挺好,但是就想自己弄个通用的 自己写了个分页的类,用的是python, 其他语言改下语法就能用了. #定义好类.class pagemanage: def __init_ ...
- php简单实用的调试工具类
<?php /* * 调试类 */ class Common_Debug { //打开错误报告 public static function showError($debug = true) { ...
- C++简单实现Log日志类轻量级支持格式化输出变量
CLog 头 代码很简单 如果需要的直接Ctrl+C ----Ctrl+V 即可 #ifndef __CLOG__ #define __CLOG__ #include <windows.h&g ...
- 20181015记录一个简单的TXT日志类
20190422添加换行以及时间记录 using System; using System.Collections.Generic; using System.IO; using System.Lin ...
- C#反射实现 C# 反射 判断类的延伸类型 使用代码生成工具Database2Sharp快速生成工作流模块控制器和视图代码 C# ADO.NET的SqlDataReader对象,判断是否包含指定字段 页面中添加锚点的几种方式 .net 简单实用Log4net(多个日志配置文件) C# 常用小点
C#反射实现 一.反射概念: 1.概念: 反射,通俗的讲就是我们在只知道一个对象的内部而不了解内部结构的情况下,通过反射这个技术可以使我们明确这个对象的内部实现. 在.NET中,反射是重要的机制, ...
- zw版_Halcon图像交换、数据格式、以及超级简单实用的DIY全内存计算.TXT
zw版_Halcon图像交换.数据格式.以及超级简单实用的DIY全内存计算.TXT Halcon由于效率和其他原因,内部图像采用了很多自有格式,提高运行速度,但在数据交换方面非常麻烦. 特别是基于co ...
- LogCook 一个简单实用的Android日志管理工具
众所周知,日志的管理是软件系统很重要的一部分,千万不可忽略其重要性.完整的日志将会在系统维护中起着异常重要的作用,就好像磨刀不误砍柴工一样,日志就像对系统进行分析的工具,工具便捷了,对系统分析起来就能 ...
- python 日志类
简介 在所有项目中必不可少的一定是日志记录系统,python为我们提供了一个比较方便的日志模块logging,通常,我们都会基于此模块编写一个日志记录类,方便将项目中的日志记录到文件中. loggin ...
随机推荐
- Eclipse ADT 插件安装慢的解决的方法
參考贴:http://blog.csdn.net/ludonghai715/article/details/6973433 在天朝非常多事情就不可避免的蛋疼,download.eclipse.org ...
- NanShan即时通讯论——HTML5的优势与劣势
原文:NanShan即时通讯论--HTML5的优势与劣势 NanShan即时通讯 学习html时才是XHTML 1.0,接着是 HTML4.01,再到HTML5,如今HTML5 開始吸引越来越多的人的 ...
- PHP - 对象转json - json转数组
前台js转为json,传给php后台,php后台接收并转为数组. 效果: -- 前台js将对象转为json: var rows = JSON.stringify(rows); 后台php接收转为数组: ...
- hibernate 一对多映射
package com.entity.onetomany; import java.util.ArrayList; import java.util.List; import javax.persis ...
- jsp截取字符串
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> < ...
- jQuery格式化时间插件formatDate
一.不传时间 $.formatDate("yyyy-MM-dd HH:mm:ss"); 二.传时间 $.formatDate("yyyy-MM-dd HH:mm:ss ...
- perl 回调必须是函数引用
[root@wx03 lib]# cat a1.pl use AE; use AnyEvent; ##定义watch my $t = AnyEvent->timer( after => 0 ...
- [置顶] 自娱自乐7之Linux UDC驱动2(自编udc驱动,现完成枚举过程,从驱动代码分析枚举过程)
花了半个月,才搞定驱动中的枚举部分,现在说linux的枚举,windows可能有差别. 代码我会贴在后面,现在只是实现枚举,你可能对代码不感兴趣,我就不分析代码了,你可以看看 在<自娱自乐1&g ...
- 使用【百度云推送】第三方SDK实现推送功能具体解释
之前介绍过怎样使用shareSDK实现新浪微博分享功能,今天介绍怎样使用百度云推送SDK实现Android手机后台推送功能. 执行效果例如以下 第一步,假设使用百度的SDK,当然要先成为百度的开发人员 ...
- NEC协议
注意: 用示波器在接收头抓的电平看起来和NEC协议刚好相反, 那是因为:HS0038B 这个红外一体化接收头,当收到有载波的信号的时候,会输出一个低电平,空闲的时候会输出高电平. 具体情况,具体分析. ...