from datetime import datetime,timedelta
import os
FILE_path = os.getcwd() +‘/log_jiexheng/‘
def log_set(msg, name =‘main‘):
now_time = datetime.now()
yes_date = now_time + timedelta(days=-1)
str_now = str(now_time).split(‘.‘)[0]
str_yes = str(yes_date).split(‘.‘)[0]
FILE_yes = FILE_path +‘%s%s‘%(name, str_yes)
FILE_main = FILE_path +‘%s%s‘%(name, str_now)
print(FILE_path,FILE_yes[:-10],FILE_main[:-10])
os.system(‘mkdir -p %s ;rm s%s ;touch %s‘%(FILE_path,FILE_yes[:-10],FILE_main[:-10]))
f = open(‘%s‘ % FILE_main[:-10], ‘a+‘)
f.write(‘[‘ + str(datetime.now()).split(‘.‘)[0] + ‘]‘ + msg + ‘\n‘)
print(‘FILE_main %s‘% FILE_main)
f.close()
log_set(msg =‘hia‘)
log_set(msg =‘hia2‘)
时间: 2024-10-12 19:57:15