Skip to content

Commit

Permalink
为日志文件增加日期分割
Browse files Browse the repository at this point in the history
  • Loading branch information
liangliangyy committed Jun 20, 2022
1 parent 0c7b8d2 commit 7640acf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions djangoblog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ def env_to_bool(env, default):
WXADMIN = os.environ.get(
'DJANGO_WXADMIN_PASSWORD') or '995F03AC401D6CABABAEF756FC4D43C7'

LOG_PATH = os.path.join(BASE_DIR, 'logs')
if not os.path.exists(LOG_PATH):
os.makedirs(LOG_PATH, exist_ok=True)

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
Expand All @@ -241,10 +245,14 @@ def env_to_bool(env, default):
'handlers': {
'log_file': {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': 'djangoblog.log',
'maxBytes': 16777216, # 16 MB
'formatter': 'verbose'
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': os.path.join(LOG_PATH, 'djangoblog.log'),
'when': 'D',
'formatter': 'verbose',
'interval': 1,
'delay': True,
'backupCount': 5,
'encoding': 'utf-8'
},
'console': {
'level': 'DEBUG',
Expand Down

0 comments on commit 7640acf

Please sign in to comment.