Skip to content

Add stacklevel parameter to logging APIs #77346

Closed

Description

@ncoghlan
BPO 33165
Nosy @vsajip, @ncoghlan
PRs
  • bpo-33165: Added stacklevel parameter to logging APIs. #7424
  • bpo-33165: Remove redundant stack unwind for findCaller() #17714
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-06-05.16:26:27.640>
    created_at = <Date 2018-03-28.09:05:21.269>
    labels = ['3.8', 'type-feature', 'library']
    title = 'Add stacklevel parameter to logging APIs'
    updated_at = <Date 2019-12-27.14:15:12.191>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2019-12-27.14:15:12.191>
    actor = 'evandrocoan'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-06-05.16:26:27.640>
    closer = 'vinay.sajip'
    components = ['Library (Lib)']
    creation = <Date 2018-03-28.09:05:21.269>
    creator = 'ncoghlan'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33165
    keywords = ['patch']
    message_count = 2.0
    messages = ['314578', '318764']
    nosy_count = 2.0
    nosy_names = ['vinay.sajip', 'ncoghlan']
    pr_nums = ['7424', '17714']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue33165'
    versions = ['Python 3.8']

    Activity

    1. ncoghlan commented on Mar 28, 2018

      @ncoghlan
      ContributorAuthor

      warnings.warn() offers a stacklevel parameter to make it easier to write helper functions that generate warnings - by passing "stacklevel=2", you can ensure the warning is attributed to the caller of the helper function, rather than to the helper function itself.

      There isn't currently a similarly clear way to write helper functions that emit logging messages - if the format includes "pathname", "filename", "module", "function", or "lineno", then those will always report the location of the helper function, rather than the caller of the helper function.

      It would be convenient if logging.debug() et al accepted a "stacklevel" parameter the same way the warnings module does (although this may require some adjustments to the Logger.findCaller method API)

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on Mar 28, 2018
    3. vsajip commented on Jun 5, 2018

      @vsajip
      Member

      New changeset dde9fdb by Vinay Sajip in branch 'master':
      bpo-33165: Added stacklevel parameter to logging APIs. (GH-7424)
      dde9fdb

    4. transferred this issue fromon Apr 10, 2022
    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

      3.8 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions