Arthur-Wu commit
This commit is contained in:
32
commons/Logger.py
Normal file
32
commons/Logger.py
Normal file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time :
|
||||
# @Author :
|
||||
# @File : Logger.py
|
||||
# @Software: PyCharm
|
||||
import logging, os, time
|
||||
from time import localtime
|
||||
|
||||
class Singleton:
|
||||
_instance = None
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls._instance is None:
|
||||
cls._instance = super(Singleton, cls).__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self, LogPath, FileName='YMAutotest'):
|
||||
def __logging(LogPath, FileName):
|
||||
datetime = time.strftime("%Y%m%d%H%M%S", localtime())
|
||||
filepath = f'{LogPath}{FileName}_{datetime}.log'
|
||||
controlshow = logging.StreamHandler()
|
||||
controlshow.setLevel(logging.INFO)
|
||||
logging.basicConfig(
|
||||
filename=filepath,
|
||||
filemode="w",
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s %(filename)s [line:%(lineno)d] %(levelname)s——: %(message)s \n',
|
||||
datefmt='%Y%m%d %H:%M:%S'
|
||||
)
|
||||
return logging
|
||||
self.logging = __logging(LogPath, FileName)
|
Reference in New Issue
Block a user