micropython / micropython/micropython-lib

asctime in logging will never output because strftime is not an attribute of time

Open
#725 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Description

Expexted behaviour:

Using this formatter the log output will include a timestamp.

logging.Formatter('%(asctime)s | %(name)s | %(levelname)s - %(message)s')

Like this:
Tue Feb 17 09:42:58 2009 | MAIN | INFO - test

Actual behaviour:

Timestamp will always be None
None | MAIN | INFO - test

Cause:

The formatTime() method checks for the strftime attribute, which does not exist in the Micropython implementation:

def formatTime(self, datefmt, record):
        if hasattr(time, "strftime"):
            return time.strftime(datefmt, time.localtime(record.ct))
        return None

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 locating the logging implementation that defines Formatter.formatTime and inspect the MicroPython time API used there. Reproduce the Formatter example from the issue, then verify that a formatted record includes a timestamp instead of None and that existing logging behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability-sre
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.