#!/usr/bin/env python
# coding:UTF-8
"""
@version: python3.x
@author:曹新健
@contact: 617349013@qq.com
@software: PyCharm
@file: 单例模式装饰日志类.py
@time: 2018/10/18 15:10
"""
import os,logging,sys,time
def singleton(cls):
instances = {}
def _singleton(*args,**kwargs):
if cls not in instances:
instances[cls] = cls(*args,**kwargs)
return instances[cls]
return _singleton
@singleton
class Logger():
def __init__(self,logfile=None):
self.logger = logging.getLogger()
formater = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(filename)s %(lineno)d '
'%(thread)d %(threadName)s %(process)d %(message)s')
if logfile == None:
cur_path = os.path.split(os.path.realpath(__file__))[0]
stime = time.strftime("%Y-%m-%d",time.localtime())
logfile = cur_path + os.sep + "log_" + stime + ".log"
else:
logfile = logfile
self.
Python:日志输出(单例模式保证logger实例唯一)
最新推荐文章于 2025-06-17 18:02:26 发布
