-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
36 lines (26 loc) · 824 Bytes
/
utils.py
File metadata and controls
36 lines (26 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# encoding=utf-8
import logging
import os
import config
import traceback
import datetime
# 自定义的日志输出
def log(msg, level = logging.DEBUG):
if not os.path.exists('log'):
os.makedirs('log')
logging.basicConfig(
filename = 'log/run.log',
format = '%(asctime)s: %(message)s',
level = logging.DEBUG
)
logging.log(level, msg)
print('%s [%s], msg:%s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), level, msg))
if level == logging.WARNING or level == logging.ERROR:
for line in traceback.format_stack():
print(line.strip())
for line in traceback.format_stack():
logging.log(level, line.strip())
def make_dir(dir):
log('make dir:%s' % dir)
if not os.path.exists(dir):
os.makedirs(dir)