Skip to content

Commit f59d739

Browse files
authored
Merge pull request #588 from liangliangyy/dev
为日志文件增加日期分割
2 parents 84a1092 + 019695a commit f59d739

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

djangoblog/settings.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ def env_to_bool(env, default):
218218
WXADMIN = os.environ.get(
219219
'DJANGO_WXADMIN_PASSWORD') or '995F03AC401D6CABABAEF756FC4D43C7'
220220

221+
LOG_PATH = os.path.join(BASE_DIR, 'logs')
222+
if not os.path.exists(LOG_PATH):
223+
os.makedirs(LOG_PATH, exist_ok=True)
224+
221225
LOGGING = {
222226
'version': 1,
223227
'disable_existing_loggers': False,
@@ -241,10 +245,14 @@ def env_to_bool(env, default):
241245
'handlers': {
242246
'log_file': {
243247
'level': 'INFO',
244-
'class': 'logging.handlers.RotatingFileHandler',
245-
'filename': 'djangoblog.log',
246-
'maxBytes': 16777216, # 16 MB
247-
'formatter': 'verbose'
248+
'class': 'logging.handlers.TimedRotatingFileHandler',
249+
'filename': os.path.join(LOG_PATH, 'djangoblog.log'),
250+
'when': 'D',
251+
'formatter': 'verbose',
252+
'interval': 1,
253+
'delay': True,
254+
'backupCount': 5,
255+
'encoding': 'utf-8'
248256
},
249257
'console': {
250258
'level': 'DEBUG',

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
coverage==6.4
22
bleach==5.0.0
3-
Django==4.0.4
3+
Django==4.0.5
44
django-compressor==4.0
55
django-haystack==3.2.1
66
django-ipware==4.0.2
@@ -19,9 +19,9 @@ python-logstash==0.4.6
1919
python-slugify==6.1.2
2020
pytz==2022.1
2121
raven==6.10.0
22-
requests==2.27.1
22+
requests==2.28.0
2323
urllib3==1.26.9
2424
WeRoBot==1.13.1
2525
Whoosh==2.7.4
2626
user-agents==2.2.0
27-
redis==4.3.1
27+
redis==4.3.3

0 commit comments

Comments
 (0)