2024-11-11 17:16:31 +08:00

33 lines
1.0 KiB
Python

#!/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)