凌的博客

您现在的位置是: 首页 > 学无止境 > python > 

python

python 记录日志的类

2020-05-02 python 739
import os, time


class Log:
    def __init__(self, file):
        self.file = file

    def record(self, content):
        with open(self.file, "a+", encoding="utf-8") as f:
            f.write("{0}:{1}\n".format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), content))

    def write(self, file, content):
        with open(file, "w", encoding="utf-8") as f:
            f.write(content)

    def outfile(self, file):
        path = os.path.dirname(file)
        return os.path.join(path, "success_" + os.path.basename(file))


文章评论

0条评论