Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stacklevel parameter to logging APIs #77346

Closed
ncoghlan opened this issue Mar 28, 2018 · 2 comments
Closed

Add stacklevel parameter to logging APIs #77346

ncoghlan opened this issue Mar 28, 2018 · 2 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ncoghlan
Copy link
Contributor

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']

    @ncoghlan
    Copy link
    Contributor Author

    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)

    @ncoghlan ncoghlan added 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 28, 2018
    @vsajip
    Copy link
    Member

    vsajip commented Jun 5, 2018

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

    @vsajip vsajip closed this as completed Jun 5, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants