1234567891011121314151617181920212223242526272829303132333435363738 |
- import time
- import sys
- class PrintLog:
- @staticmethod
- def print(content):
- script_path = sys.path[0]
- logfile = script_path + '/log/data/' + PrintLog.script_name() + '_' + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
- file = open(logfile, 'a', encoding='utf8')
- content = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' ' + content
- file.write(content + '\n')
- # 关闭文件
- file.close()
- @staticmethod
- def script_name() :
- argv0_list = sys.argv[0].split('/')
- script_name = argv0_list[len(argv0_list) - 1] # get script file name self
- script_name = script_name[0:-3] # remove '.py'
- return script_name
- @staticmethod
- def write(content, file_name):
- script_path = sys.path[0]
- logfile = script_path + '/log/data/' + PrintLog.script_name() + '_' \
- + file_name + '_' + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
- file = open(logfile, 'a', encoding='utf8')
- content = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' ' + content
- file.write(content + '\n')
- # 关闭文件
- file.close()
|