GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bad logging documentation {}-formatting placeholder · Issue #109451 · python/cpython

bad logging documentation {}-formatting placeholder #109451

New issue
Copy link
New issue
Copy link
Closed
Closed
bad logging documentation {}-formatting placeholder#109451
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc direasy

Description

@AlberLC
AlberLC
opened on Sep 15, 2023
Issue body actions

Documentation

%-formatting (It works)

import logging
logging.basicConfig(filename='example.log', format='%(msecs)03d - %(message)s')
logging.warning('foo')

example.log:

273 - foo

✅

Now using the the modern {} format syntax, as the documentation says (doesn't work)

image

import logging
logging.basicConfig(filename='example.log', format='{msecs:03d} - {message}', style='{')
logging.warning('foo')

❌

Exception:

--- Logging error ---
Traceback (most recent call last):
  File "...\Python\Python310\lib\logging\__init__.py", line 1100, in emit
    msg = self.format(record)
  File "...\Python\Python310\lib\logging\__init__.py", line 943, in format
    return fmt.format(record)
  File "...\Python\Python310\lib\logging\__init__.py", line 681, in format
    s = self.formatMessage(record)
  File "...\Python\Python310\lib\logging\__init__.py", line 650, in formatMessage
    return self._style.format(record)
  File "...\Python\Python310\lib\logging\__init__.py", line 440, in format
    return self._format(record)
  File "...\Python\Python310\lib\logging\__init__.py", line 458, in _format
    return self._fmt.format(**values)
ValueError: Unknown format code 'd' for object of type 'float'
Call stack:
  File "...\main.py", line 26, in <module>
    logging.warning('foo')
Message: 'foo'
Arguments: ()

Proposed fix

Use {msecs:03.0f} placeholder.

import logging
logging.basicConfig(filename='example.log', format='{msecs:03.0f} - {message}', style='{')
logging.warning('foo')

example.log:

273 - foo

✅

Linked PRs

  • gh-109451:bad logging documentation {}-formatting placeholder #109460
  • gh-109451: Fix logging documentation #109465
  • [3.11] gh-109451: Fix wrong format specifier in logging documentation (GH-109465) #109482
  • [3.12] gh-109451: Fix wrong format specifier in logging documentation (GH-109465) #109483

Activity

  1. AlberLC
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Sep 15, 2023
  2. sobolevn commented on Sep 15, 2023

    @sobolevn
    sobolevn
    on Sep 15, 2023
    Member
    More actions

    Please, send a PR :)

  3. sobolevn
    added
    easy
    on Sep 15, 2023
  4. AlberLC
    added a commit that references this issue on Sep 15, 2023

    Fix logging documentation (python#109451)

    00ffdd8
  5. vsajip
    added a commit that references this issue on Sep 16, 2023

    gh-109451: Fix wrong format specifier in logging documentation (GH-10…

    929cc4e
  6. miss-islington
    added 2 commits that reference this issue on Sep 16, 2023

    pythongh-109451: Fix wrong format specifier in logging documentation (p…

    93a85e7

    pythongh-109451: Fix wrong format specifier in logging documentation (p…

    c12f079
  7. AlberLC
    closed this as completedon Sep 16, 2023
  8. vsajip
    added a commit that references this issue on Sep 16, 2023

    [3.11] gh-109451: Fix wrong format specifier in logging documentation (…

    9b38cbe
  9. Yhg1s
    added a commit that references this issue on Sep 17, 2023

    [3.12] gh-109451: Fix wrong format specifier in logging documentation (…

    cc12f66
  10. csm10495
    added a commit that references this issue on Sep 28, 2023

    pythongh-109451: Fix wrong format specifier in logging documentation (p…

    d152179
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc direasy

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.