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 option to change print function #145

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

barabum0
Copy link

I added logger_function parameter to Debug() class that replaces print if set. Here is an example of usage with loguru:

from devtools import Debug
from loguru import logger

debug = Debug(logger_function=logger.debug)

test_object = {
    "string": "test",
    "integer": 123,
    "nested": {
        "key": "value"
    }
}
debug(test_object)
# 2023-10-29 18:38:45.211 | DEBUG    | devtools.debug:__call__:127 - logger_func_test.py:13 <module>
#     test_object: {
#         'string': 'test',
#         'integer': 123,
#         'nested': {
#             'key': 'value',
#         },
#     } (dict) len=3

@codecov
Copy link

codecov bot commented Oct 29, 2023

Codecov Report

Merging #145 (fb8c506) into main (ec406ff) will decrease coverage by 0.26%.
The diff coverage is 60.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #145      +/-   ##
==========================================
- Coverage   96.29%   96.03%   -0.26%     
==========================================
  Files           8        8              
  Lines         729      732       +3     
  Branches      111      112       +1     
==========================================
+ Hits          702      703       +1     
- Misses         21       22       +1     
- Partials        6        7       +1     
Files Coverage Δ
devtools/debug.py 98.48% <60.00%> (-1.52%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec406ff...fb8c506. Read the comment docs.

@barabum0
Copy link
Author

barabum0 commented Oct 29, 2023

added some commits to please lint checker

@barabum0 barabum0 changed the title Add logging_function parameter Add option to change print function Oct 29, 2023
@barabum0
Copy link
Author

CI / lint (pull_request) Failing after 1m

I actually don't know whats wrong with my code (if so). But my feature is working correctly, so please review and merge it

*,
warnings: 'Optional[bool]' = None,
highlight: 'Optional[bool]' = None,
logger_function: 'Optional[Callable[[str], None]]' = None,

Choose a reason for hiding this comment

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

If logger_function would have the same signature as print, you could initialize it to print per default.
That way you can get rid of the conditional code in __call__. One might have to wrap a logger into a lambda to ignore the additonal file/flush arguments.

@maltevesper
Copy link

CI / lint (pull_request) Failing after 1m

I actually don't know whats wrong with my code (if so). But my feature is working correctly, so please review and merge it

While I am not involved with the project, you might be able to fix your issue: apparently you overindented something, try reformatting with black and committing. You can see the ci issue here: https://github.com/samuelcolvin/python-devtools/actions/runs/6684613574/job/18162063139?pr=145#step:6:158

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.

None yet

2 participants