[Answered ]-Why is my Python Django logging file empty when my console log is not?

1👍

Although you are setting the configuration for a logger, you aren’t logging the info into the file:

import logging

logger = logging.getLogger(__name__)
logger.info("blah blah blah")  # Or loggger.error(..), or whatever

I would recommend getting a closer look to the docs (the link goes to the specific part of using this logger object).

What I truly unknown is how to add a signal when running the development server to trigger the piece of code above.

1👍

As you can see in https://docs.djangoproject.com/en/dev/topics/logging/#using-logging
Once you have configured your loggers, handlers, filters and formatters, you need to place logging calls into your code. Using the logging framework is very simple.

So what you see in your console is not really logging but something else

If you want to get the stuff in your console into my file you can use pipe and tee:

[the command you want to run] | tee you_log_file.log

For example:

ifconfig | tee ifconfig.log

you will get the output in your console and the file ifconfig.log.

0👍

What’s your code for logging logs? You need to obtain logger for logging into specified logger.
I notice that you don’t even give a name to your logger, so I suppose you just use “logging.error, logging.debug, etc”

‘loggers’: {
”: {
‘level’: ‘DEBUG’,
‘handlers’: [‘console’,’applogfile’]
},

Leave a comment