Update nologs.py
Browse files
nologs.py
CHANGED
@@ -3,6 +3,10 @@ import sys
|
|
3 |
import logging
|
4 |
import os
|
5 |
|
|
|
|
|
|
|
|
|
6 |
# 配置日志
|
7 |
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
8 |
|
@@ -30,4 +34,4 @@ except Exception as e:
|
|
30 |
finally:
|
31 |
# 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
|
32 |
logging.getLogger().removeHandler(console_handler)
|
33 |
-
console_handler.close()
|
|
|
3 |
import logging
|
4 |
import os
|
5 |
|
6 |
+
# 获取当前脚本所在的目录
|
7 |
+
script_dir = os.path.dirname(os.path.realpath(__file__))
|
8 |
+
log_file = os.path.join(script_dir, "logs.txt")
|
9 |
+
|
10 |
# 配置日志
|
11 |
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
12 |
|
|
|
34 |
finally:
|
35 |
# 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
|
36 |
logging.getLogger().removeHandler(console_handler)
|
37 |
+
console_handler.close()
|