2016-11-21 36 views

回答

3

這是一個簡單的Linux重定向,所以它應該是這個樣子:

python manage.py runserver 0.0.0.0:8080 >> log.log 2>&1 

請注意,我已經設置8080的本地端口,你應該把它根據你的項目改變。

PS:此方法(管理runserver)只能用於開發,不適用於部署

+1

語法使用泊塢窗: CMD [ 「/ bin/sh的」, 「-c」,「/manage.py的runserver 0.0.0.0:3000> > log.log 2>&1「] – Vingtoft

1

這些是一些示例設置,應確保將日誌寫入控制檯和文件。您可以添加/修改這個在你的開發設置:

LOGGING = { 
    'version': 1, 
    'disable_existing_loggers': True, 
    'formatters': { 
     'standard': { 
      'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s' 
     }, 
    }, 
    'handlers': { 
     # this is what you see in runserver console 
     'console': { 
      'class': 'logging.StreamHandler', 
      'formatter': 'standard', 
     }, 
     # this handler logs to file 
     #▼▼▼▼ this is just a name so loggers can reference it 
     'file': { 
      'class': 'logging.FileHandler', 
      # choose file location of your liking 
      'filename': os.path.normpath(os.path.join(BASE_DIR, '../../logs/django.log')), 
      'formatter': 'standard' 
     }, 
    }, 
    'loggers': { 
     # django logger 
     'django': { 
      # log to console and file handlers 
      'handlers': ['console', 'file'], 
      'level': os.getenv('DJANGO_LOG_LEVEL', 'ERROR'), # choose verbosity 
     }, 
    }, 
} 
+0

這僅在ERROR日誌級別打印日誌記錄。因此結果與runserver命令不相似。 我不知道runserver命令使用什麼日誌級別,請讓我知道如果你發現:) – Vingtoft