tintoy / seqlog

Python logging integration for Seq (https://getseq.net)
https://seqlog.readthedocs.io/
MIT License
17 stars 11 forks source link

how to use seqlog in flask #12

Closed jiangpan closed 3 years ago

jiangpan commented 6 years ago

Description

Describe what you were trying to get done. Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
tintoy commented 6 years ago

Hi - it's been a while since I used Flask; I'll look into it and get back to you.

tintoy commented 6 years ago

This is a starting point for configuring Flask logging but I'll see if I can write up some example YAML for it:

http://flask.pocoo.org/docs/1.0/logging/

(work's pretty crazy today so I probably won't get to this until tomorrow, though)

piotrmaslanka commented 3 years ago

You first set up your logging:

seqlog.configure_from_file(filename)

And then you can use my excellent library called flask-requests-logging to log Flask to it:

app = flask.Flask(__name__)
FlaskRequestsLogging(app, pass_as_extras=False)

pass_as_extras is extra helpful, as it helps to deal with these kinds of statements, which are frequently used if you're using seqlog:

logger.log('Testing logging %s', 2, device_id='2')

vs the more Pythonic

logger.log('Testing logging %s', 2, extras={'device_id': '2'})

or extra I don't really remember now.

Works like a charm for me. Closing this issue.