0

Flask writes some logging lines witout me setting anything special or adding any extra lines, eg:

127.0.0.1 - - [08/Jul/2020 10:24:46] "GET /swaggerui/favicon-32x32.png HTTP/1.1" 200 -
127.0.0.1 - - [08/Jul/2020 10:24:46] "GET /swagger.json HTTP/1.1" 200 -
127.0.0.1 - - [08/Jul/2020 10:24:52] "GET /random_resource/1/1 HTTP/1.1" 404 -

I have been learning the logging module and I want to implement a better logging without having to actually add the log calls everytime:

log.warn('Warning message')

I would like to modify the existing log that is being used and modify it at my will without having to add the calls to the logging in everyline of the module.

EDIT

Using app.logger doesnt solve the issue as it produces a completely different format:

app.logger.info(f"user_id:{request.view_args['user_id']}")

[2020-07-08 11:56:33,894] INFO in __init__: user_id:1

1 Answer 1

1

Flask's logging instance is available via app.logger

Also see the official documentation:

https://flask.palletsprojects.com/en/1.1.x/logging/?highlight=logging

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

2 Comments

Sorry but no, the application itself still produces logs like: 127.0.0.1 - - [08/Jul/2020 11:56:33] "GET /random_resource/1/1 HTTP/1.1" 404 -. If I use your suggestion it looks like a different format: [2020-07-08 11:56:33,894] INFO in init: user_id:1
I am sorry. If the official documentation is wrong, please file an issue at Flask's Bug tracker at GitHub.

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.