python log日志

 1 # -*- coding: utf-8 -*-
 2 import logging, logging.handlers, os, sys
 3 
 4 
 5 '''
 6 #=============================================================================
 7 # Author: xiaobaiyun
 8 # Email: 
 9 # FileName: mylog.py
10 # Description: python 日志相关操作
11 # Version: 1.0
12 # LastChange: 2016-10-10 23:21:20
13 # History: 
14 #=============================================================================
15 '''
16 #以下注释可以打印当前行号,调用该log模块时最好能带上,将行号一同写入日志
17 #print sys._getframe().f_lineno
18 
19 class myLogging():
20   def __init__(self,log_filename=r'c:\\testlog.log'):
21     logging.handlers.RotatingFileHandler(log_filename, maxBytes=1024)
22     logging.basicConfig(level = logging.DEBUG,
23       format = '%(asctime)s %(filename)s [ %(levelname)s ] %(message)s',
24       datefmt = '%a, %d %b %Y %H:%M:%S',
25       filename = log_filename,
26       filemode = 'a')
27 
28   def debug(self,log_line=None,log_message='This is debug message'):
29     logging.debug('[line:%s] '%(log_line) + log_message)
30 
31   def info(self,log_line=None,log_message='This is info message'):
32     logging.info('[line:%s] '%(log_line) + log_message)
33 
34   def warning(self,log_line=None,log_message='This is warning message'):
35     logging.warning('[line:%s] '%(log_line) + log_message)
36 
37   def error(self,log_line=None,log_message='This is error message'):
38     logging.error('[line:%s] '%(log_line) + log_message)
39 if __name__=="__main__":
40   #myLogging().debug(log_line = sys._getframe().f_lineno, log_message = 'This is my debug message')
41   myLogging(log_filename=r'c:\\test.log').debug(log_line = sys._getframe().f_lineno, log_message = 'This is my debug message...')
42   raw_input('exit')

 

转载于:https://www.cnblogs.com/xiaobaiyun/p/5990805.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值