pcdshub / pcdshub/pcdsutils

Log helper snippet: determine_log_stacklevel

Open
#64 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2
Forks
6
Avg merge
7d 11h
Merged PRs (30d)
1

Description

Snippet

Could be useful for some applications - determining dynamically how to configure Logger.log(..., stacklevel=_) when your message is sourced from some utility script

import inspect


def determine_log_stacklevel(*files_to_ignore: str) -> int:
    """
    Determine the stack level for logging exceptions, based on the current
    code stack.
    """
    stacklevel = 1
    # stack()[1:] skips determine_log_stacklevel()
    for frame_info in inspect.stack()[1:]:
        if frame_info.filename not in files_to_ignore:
            break
        stacklevel += 1
    return stacklevel

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

The issue names no repository file, entry point, or test; it only provides a Python helper using inspect.stack() for Logger.log(..., stacklevel=_). Start by reviewing the utility modules and test layout, then clarify where this helper belongs and what integration is expected. Done should include an agreed location and coverage for the intended stack-level behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.