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

Location information in log show pli.py instead of logging location #2

Open
texasaggie97-zz opened this issue Aug 20, 2019 · 1 comment

Comments

@texasaggie97-zz
Copy link

python_log_indenter is very useful and what I was looking for. I have found one small thing.

I have (%(filename)s:%(funcName)s:%(lineno)s) in the formatted string that I am using for logging.

When using IndentedLoggerAdapter() the file location shows pli.py instead of the actual location that has the logging statement. I don't know the inner workings of Python logging well enough to know if there is a way to pass that location information on to the actual logging function.

@dstrohl
Copy link
Owner

dstrohl commented Aug 21, 2019

Yeah, that's a challange I hadn't thought fo at the time, though it's a common issue with things like this.

Later in a different program I made this function...

def get_line_no(offset=0, sep='\n'):
try:
raise NotImplementedError()
except NotImplementedError:
formatted_lines = traceback.format_stack()
tmp_stack = []
start = False
for line in formatted_lines:
if 'unittest' in line.lower() or 'django' in line.lower():
start = True
continue
if '\who_helpers\test_helpers.py' in line:
continue
if not start:
continue

        tmp_stack.append(line)

    return ''.join(tmp_stack)

it's not a perfect answer to your issue, but it might give you a starting point to addressing it somehow.

Offhand I'm not sure how to "fix" it automatically in the code. I will have to dive a bit deeper to figure out how the logging system does the lookups for things like line numbers. it might come down to adding another variable (like 'line_num" that takes this into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants