2

Help me understand please. I'm new in python. I'm writing WSGI app. And I want to turn loggining on. I do:

logger = logging.getLogger(__name__)

then I want to print something in log:

logger.exception("Some exception...")

Where it all stores? Only in console output or there is a file somewhere on the server? If so, where I can find this file?

2 Answers 2

1

Actually, you have to specify the file yourself, e.g. with logging.basicConfig():

logging.basicConfig(filename="/path/to/your/logfile.log")

Logging can be quite a complex matter sometimes, I'd suggest you read the HOWTO.

Sign up to request clarification or add additional context in comments.

Comments

1
import logging
logging.error("Error")  # Prints to console

This how to write a log to a file

logging.basicConfig(filename='Error.log',level=logging.ERROR)
logging.error('Error')

Opening the Error.log you will see

ERROR:root:Error

More info here

3 Comments

Where does "And this, too" come from?
I would not log a message "Error" with level WARNING :)
Rakesh, I don't think that was what @Tichodroma was talking about. Your edit sets the logging level to logging.ERROR, which means nothing will get logged because a warning is less important than an error. Tichodroma's comment seems to refer to your calling warning() with a message consisting of Error. Indeed, in that case, you probably should call error() instead :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.