Forums

How to set up logging in Django

I am new to Python/Django. I see that to log messages one can do something like the following in code

import logging
logger = logging.getLogger(__name__)

logger.info ('My message')

When I do that nothing happens. I am obviously missing some configuration. Does pythonanywhere provide any default configuration? How is this configuration done and where?

Thank you

I actually had the logging in the wrong place. I see the messages in error.log file.

I am still curious, where is the log configuration done?

It's done in the server configuration.

Can you please explain where did you have logging and where is the correct place because i cannot see anything in error.log file and I am having this code:

import logging
logger = logging.getLogger(__name__)
logger.info ('My message')

on top of my settings.py file.

[edit by admin: formatting]

Are you sure that the file that you have that in is actually the one that is being used by your web app?

I think so because the changes I make to this file(settings.py) change both the behavior of my web app and the error.log file

What happens if you do logger.error instead of logger.info?

tried that too.It still doesn't show anything in error.log file

How does your logging configuration in Django settings looks like?