[Django]-How to write all logs of django console to to custome file file?

2👍

Your problem is in the filename, You need to set it to the right path!

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
    'file': {
        'level': 'DEBUG',
        'class': 'logging.FileHandler',
        'filename': os.path.join(BASE_DIR,'APPNAME.log'),
    },
},
'loggers': {
    'django': {
        'handlers': ['file'],
        'level': 'DEBUG',
        'propagate': True,
    },
},
}

2👍

Replace with a static route and do not forget to give the file permission.

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
    'file': {
        'level': 'DEBUG',
        'class': 'logging.FileHandler',
        'filename': '/home/user/proyect/debug.log,
    },
},
'loggers': {
    'django': {
        'handlers': ['file'],
        'level': 'DEBUG',
        'propagate': True,
    },
},
}

1👍

It is probably because you have no logs for django handler.
Define one with empty string as a default one:

...
'loggers': {
    '': {
        'handlers': ['file'],
        'level': 'DEBUG',
        'propagate': True,
    },
},
...

The ‘django’ logger is used in django only once – in the library itself.
When creating a logger you give it a name – usually something like this: log = logging.getLogger(__name__) – where a name is the name of the module which it will be used in.
You can specify and configure different modules to write/report in a different way.

Leave a comment