Pytorch-lightning: Switch from print to logging

Created on 2 Oct 2019  路  16Comments  路  Source: PyTorchLightning/pytorch-lightning

Use logging instead of print. (@Ir1d you brought this up before)

Suggested by @adefazio

enhancement help wanted

Most helpful comment

I suppose f-strings are preferred?
should we exposure logger as an option, since I prefer loguru, while others might like something else.

All 16 comments

hey @williamFalcon could you just guide me to the files that needs print to be changed to logging and i'll do it. Thanks.

I think that we were talking about it already a few months back :] happy to see it pass O:-)
@williamFalcon could you draw what kind of messages should be info and debug?

@humandotlearning please use lazy formating

logging.info('Epoch %05d: %s did not improve', epoch + 1, self.monitor)

see: https://stackoverflow.com/a/52012660/4521646

I suppose f-strings are preferred?
should we exposure logger as an option, since I prefer loguru, while others might like something else.

Given a second thought, what about adding a info and some debug function into LightningLoggerBase?
Something like: self.logger.info() , and users will be free to use whatever logger they like by specifying in custom logger.

However: after a quick search. their are certain functions which dont have access to LoggerBase at this moment. For example the callback

Please use f-strings!

okay as @williamFalcon suggested i'll go with f-string. I have done a performance comparison if anyone is interested.
https://colab.research.google.com/drive/1J6-SFq5nDGTYDH7GIpzixbjYS0UvZ30E

@humandotlearning @lr1d already started in #457

actually I'm stuck with how to let users select custom printing function? Any idea on this?

@Ir1d what do you mean by custom printing function? logging.info/debug/warning / print()... ?

@Borda I mean using other libraries such as loguru. But yes, what if someone wants to use debug/warning or other stuffs

it is nice library, but I would follow the same strategy as for PyTorch, do not include anything extra until it is really needed so I would sta just with the standard logging , @williamFalcon ?

@Borda Yes, and I believe @williamFalcon is aware of this fact :joy:

It's possible to use f2format to convert f-strings to str.format, to be compatible with Python <=3.5

@ethanjperez amazing haha. it鈥檚 finally happening :)

i think it鈥檚 a good place to start for a PR @ethanjperez ?

@ethanjperez it is true, but I am not sure that we do not want to have this "".format() formatting...
it works exactly as it is written in the package description:

# the original code
var = f'foo{(1+2)*3:>5}bar{"a", "b"!r}boo'
# after `f2format`
var = 'foo{:>5}bar{!r}boo'.format((1+2)*3, ("a", "b"))

@williamFalcon ^^

Was this page helpful?
0 / 5 - 0 ratings

Related issues

williamFalcon picture williamFalcon  路  3Comments

justusschock picture justusschock  路  3Comments

baeseongsu picture baeseongsu  路  3Comments

edenlightning picture edenlightning  路  3Comments

mmsamiei picture mmsamiei  路  3Comments