Skip to content

Instantly share code, notes, and snippets.

@EmadMokhtar
Created May 4, 2020 09:01
Show Gist options
  • Save EmadMokhtar/c24710aa216a9f201107eae06a7e4d19 to your computer and use it in GitHub Desktop.
Save EmadMokhtar/c24710aa216a9f201107eae06a7e4d19 to your computer and use it in GitHub Desktop.
Django Recipies
# Add this part to settings to get file logger in your Django app.
# Log files path on Production environment
LOGS_DIR = '/logs'
# Check if the directory exists and if not create it
if not os.path.exists(LOGS_DIR):
os.mkdir(LOGS_DIR)
# Handler
'app-file-log': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(LOGS_DIR, 'rtb.log'),
'maxBytes': 1024 * 1024 * 15, # 15MB
'backupCount': 10
},
# Assign the handler to a logger
'logger_name': {'level': 'INFO', 'handlers': ['app-file-log']}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment