Skip to content

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

sizhky added 2 commits March 17, 2021 20:44
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

level=level,
path=path,
line_no=record.lineno,
line_no=f'{record.funcName}:{record.lineno}',
Copy link
Member

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
Member

Choose a reason for hiding this comment

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

Yep

@willmcgugan
Copy link
Member

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