Skip to content

user_agent field as a <user_agent> object instead of a string? #51

@miaoluda

Description

@miaoluda

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:

'user_agent': ctx.request.user_agent,

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,
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions