samuelcolvin / python-devtools

Dev tools for python
https://python-devtools.helpmanual.io/
MIT License
974 stars 48 forks source link

[Feature Request] Can debug print output to a configured logger? #122

Open zhuoqun-chen opened 1 year ago

zhuoqun-chen commented 1 year ago

debug is a wonderful tool and saved me a lot of time for debugging. And In my projects, I used to configure my owner logger for recording some running information. And now I use both debug() and logger.debug().

However, when they are used together, the terminal looks like this:

image

But another tool I'm using called Hydra can also format some information into its configured logger, and the result looks like this: image

So I assume if debug can offer similar option, it will be amazing.

Can your team kindly consider to support this feature?

Appreciated your maintenance. Thanks!

alexmojaki commented 1 year ago

What about debug.format?

zhuoqun-chen commented 1 year ago

What about debug.format?

Hi alexmojaki,

Thanks for the advice! But currently I'm not sure how to use debug.format function to do this because the integration with a custom logger is not listed in the documentation of devtools.

Or are you suggesting something like:

a = torch.tensor([1, 2, 3])
logger.debug(debug.format(a))

Could you please give me more explanations or examples? Thx again.

samuelcolvin commented 1 year ago

debug.format() takes the same arguments debug() but returns the formatted string instead of printing it.