flask-track-usage
flask-track-usage copied to clipboard
user_agent field as a <user_agent> object instead of a string?
Python 3.5.2 flask 0.12.2
I am trying to save the log in a file as OutputWriter(output=open('page_view.log','a'), transform=lambda s: str(s))
. In the output file I find that user_agent shows as 'user_agent': <UserAgent 'chrome'/74.0.3729.169>
It should be fine for storage backends, but it's a little bit problematic for an output file. (i.e json.dumps get TypeError: <UserAgent 'chrome'/74.0.3729.169> is not JSON serializable
)
For the user_agent field: https://github.com/ashcrow/flask-track-usage/blob/cceb0d205c0690e0e48ecad9be8c67b1e5afa1aa/src/flask_track_usage/init.py#L160
Is it better like this?
'user_agent': ctx.request.user_agent.string,
or
'user_agent': {
'browser':ctx.request.user_agent.browser,
'language':ctx.request.user_agent.language,
'platform':ctx.request.user_agent.platform,
'version':ctx.request.user_agent.version,
}