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

Function Name in Logger by Default #1113

Closed
wants to merge 2 commits into from
Closed

Conversation

sizhky
Copy link

@sizhky sizhky commented Mar 17, 2021

Add function name to logging, and works by default

[03/17/21 19:31:58] INFO          MESSAGE          MESSAGE                             app.py:supervised_api:55

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

Really wanted to have function name as part of file name and line number

Like so

`app.py:supervised_api:74`
Add func name in between file name and line number
@sizhky
Copy link
Author

sizhky commented Mar 17, 2021

The edit is literally one line, and works by default, so I did not want to add tests/documentation to the code.
But I believe the feature will be a good addition to the library nonetheless

@@ -200,7 +200,7 @@ def render(
time_format=time_format,
level=level,
path=path,
line_no=record.lineno,
line_no=f'{record.funcName}:{record.lineno}',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may break typing since line_no is an integer.

Copy link
Author

@sizhky sizhky Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you suggest I add a new keyword argument at RichHandler? Something like show_function_name

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

@willmcgugan
Copy link
Collaborator

I wouldn't want to do this by default, mainly for space issues--a long function name could leave little space for the rest of the log text.

It would be a nice addition, but it would have to be optional and off by default.

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

Successfully merging this pull request may close these issues.

2 participants