import logging
import os
import time
class Loggin:
def __init__(self):
self.leve=1
@property
def logging(self):
if self.leve == 1:
return logging
else:
logging.basicConfig(format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',
level=logging.DEBUG)
return logging
def warning(self, warning):
self.logging.warning(warning)
self.loggin_txt("【%s】【warning】->%s" % (self.time, warning))
def debug(self, debug):
self.logging.debug(debug)
if self.leve == 0:
self.loggin_txt("【%s】【debug】->%s" % (self.time, debug))
def info(self, info):
self.logging.info(info)
if self.leve == 0:
self.loggin_txt("【%s】【info】->%s" % (self.time, info))
def loggin_txt(self, txt):
loggin_path = os.path.join(os.getcwd(), "loggin/", "test.txt")
print(loggin_path)
print(txt)
with open(loggin_path, 'a', encoding='utf-8') as f:
f.write(str(txt) + '\n')
@property
def time(self):
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
if name == ‘main’:
Loggin().warning(“warning”)
Loggin().debug(“debug”)
Loggin().info(“info”)