Skip to content

Commit d89be31

Browse files
committed
optimize logs
1 parent 92ad4b3 commit d89be31

5 files changed

Lines changed: 29 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
.DS_Store
99
storage/Positions
1010
config.yaml
11+
12+
logs/*

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ cp config.yaml.example config.yaml
116116
```
117117
$ python main.py
118118
```
119-
运行结果查看日志文件[sequoia.log](sequoia.log)
119+
运行结果查看 logs 目录下生成的日志文件 格式为 `logs/sequoia-$YEAR-$MONTH-$DAY-$HOUR-$MINUTE-$SECOND.log`
120+
如:`logs/sequoia-2023-03-03-20-47-56.log`
120121
121122
### 服务器端运行
122123
#### 定时任务

main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
import settings
77
import schedule
88
import time
9+
import datetime
910

1011

1112
def job():
1213
if utils.is_weekday():
1314
work_flow.prepare()
1415

1516

16-
logging.basicConfig(format='%(asctime)s %(message)s', filename='sequoia.log')
17+
current_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
18+
log_filename = 'logs/sequoia-{}.log'.format(current_time)
19+
logging.basicConfig(format='%(asctime)s %(message)s', filename=log_filename)
1720
logging.getLogger().setLevel(logging.INFO)
1821
settings.init()
1922

tests/local_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# !/usr/bin/env python
2+
# -*-coding:utf-8 -*-
3+
4+
"""
5+
# File : local_test
6+
# Time :2023/3/3 20:40
7+
# Author :qunzhong
8+
# version :python 3.8
9+
# Description:
10+
"""
11+
import datetime
12+
13+
if __name__ == '__main__':
14+
# just for local test
15+
current_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
16+
log_filename = 'sequoia-{}.log'.format(current_time)
17+
print(log_filename)

tests/test_push.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from push import strategy
66
from push import statistics
77
import logging
8+
import datetime
89

910

1011
def test_push():
@@ -18,5 +19,7 @@ def test_strategy():
1819
strategy("1")
1920

2021

21-
logging.basicConfig(format='%(asctime)s %(message)s', filename='../sequoia.log')
22+
current_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
23+
log_filename = 'logs/test-push-{}.log'.format(current_time)
24+
logging.basicConfig(format='%(asctime)s %(message)s', filename=log_filename)
2225
logging.getLogger().setLevel(logging.INFO)

0 commit comments

Comments
 (0)