How to save logs, to S3Boto3Storage, with Django Logging

64 Views Asked by At

I need to save my logs to a file on dedicated storage (using S3BotoStorage). I haven't found any working solution yet. Does anyone know how to make it work? I need to incorporate something similar to logging.handlers.RotatingFileHandler with backups.

This is my settings.py:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'format': '%(asctime)s %(levelname)s %(name)s %(message)s'
        },
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'standard',
            'filters': [],
        },
        'file': {
            'level': 'INFO',
            'class': 'fundamental.cdn.backends.LogsRootS3BotoStorage',
            'formatter': 'standard',
            'filename': 'logs.log',
        },
    },
    'loggers': {
        logger_name: {
            'level': 'INFO',
            'propagate': True,
            'handlers': [],#['file'],
        } for logger_name in ('django', 'django.request', 'django.db.backends', 'django.template', 'articles')
    },
    'root': {
        'level': 'DEBUG',
        'handlers': ['console'],
    }
}

this is cdn.backed

from storages.backends.s3boto3 import S3Boto3Storage

...

class LogsRootS3BotoStorage(S3Boto3Storage):
    location = "logs"
    file_overwrite = False
0

There are 0 best solutions below