nhairs / nhairs/python-json-logger

asctime handling

Open
#17 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

open for discussion
Dominant language
Python
Stars
270
Forks
21
PR merge metrics
No merged PRs in 30d

Description

Currently using the asctime field will produce a string that is formatted separately from the JSON encoders.

By default it is produced by logging.Formatter.formatTime which uses converter=time.localtime and datefmt.

It feels like instead it should be a datetime encoded by the JSON encoder. However doing this would raise other questions like:

  • What do we do with the datefmt argument?
  • What do we do with the converter attribute?
  • Do we remove the timestamp argument?
    • This could be converted to an alias that adds asctime to required_fields and "asctime": "timestamp" to rename_fields. Though then what do we do if asctime and timestamp are used?
    • I'll note that there doesn't appear to be any reasoning for why timestamp was added included in the commit that added it. Searching old issues doesn't surface anything either.
  • Do we support time zones that aren't UTC?
  • What about users still using asctime, datefmt, and converter?
    • Searching old issues - it looks like there people who are using these to control the output of asctime.

As such any decision to move to using the JSON encoder or changing / removing timestamp is likely a breaking change which we probably want to avoid for as long as possible.

Another approach would be to set "saner" defaults for formatTime or (datefmt and converter). This could be considered a non-breaking change (anyone using defaults would experience the change, but anyone using custom shouldn't see breakages).

Another approach would be to use some kind of "opt-in" keyword argument that toggles new behaviour and otherwise uses old behaviour.

Perhaps in the short term all we do is update the docs to suggest that using timestamp over asctime.

Opinions welcome

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the current handling of asctime, datefmt, converter, and timestamp, then compare it with Python's logging.Formatter.formatTime behavior. The issue does not name implementation files or tests; work is not ready until the compatibility questions and preferred approach are decided, with documentation updates as the possible short-term outcome.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
24/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.