目录
写txt方式
# 动态生成的日志文件名
log_filename = 'application.txt'
# 打开文件(如果不存在则创建)
with open(log_filename, 'a') as log_file:
# 写入日志信息
log_file.write("DEBUG - This is a debug message\n")
log_file.write("INFO - This is an info message\n")
log_file.write("WARNING - This is a warning message\n")
log_file.write("ERROR - This is an error message\n")
log_file.write("CRITICAL - This is a critical message\n")
print("Log messages have been written to", log_filename)