Skip to content

Use logging instead of print statements #207

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

Closed
mitar opened this issue Sep 6, 2017 · 11 comments
Closed

Use logging instead of print statements #207

mitar opened this issue Sep 6, 2017 · 11 comments

Comments

@mitar
Copy link
Contributor

mitar commented Sep 6, 2017

Code is full of print statements. Please use logging so that one can intercept output and control noisiness.

@haiy
Copy link

haiy commented Sep 27, 2017

+1

@zsdonghao
Copy link
Member

Hi, to disable the printing, you can use:

>>> print("You can see me")
>>> with tl.ops.suppress_stdout():
>>>     print("You can't see me")
>>> print("You can see me")

@haiy
Copy link

haiy commented Sep 28, 2017

hi @zsdonghao. it's not about how to suppress print, it's about logging info with more control.If we use logging, then we can config what and where to output .When we want to deploy tl to production environment as service, we need it to log the normal and exception messages.Besides we found some globals defined in layers.py

set_keep = globals()
set_keep['_layers_name_list'] =[]
set_keep['name_reuse'] = False

,this piece of code make tl hard to deploy as service for multiple users.

@mitar
Copy link
Contributor Author

mitar commented Sep 28, 2017

I second everything @haiy said. Both of those two pieces have bitten us as well.

@zsdonghao
Copy link
Member

zsdonghao commented Sep 28, 2017

@haiy For production, as I know, people usually use TensorFlow Serving, threading is not necessary. May be I didn't get you point? or there are some reasons threading is better?

@mitar
Copy link
Contributor Author

mitar commented Sep 28, 2017

Sometimes threading is used under you. See here and here.

@zsdonghao
Copy link
Member

@mitar Thanks, I will think about it carefully ~

@tomtung
Copy link
Contributor

tomtung commented Oct 11, 2017

Totally agree with the concerns over using print instead of logging. Things like suppress_stdout and disable_print suppresses stdout globally regardless of whether the prints are from the library, which feels quite overreaching. Logging seems to be more suitable here; see When to use logging.

I think we could just add the following to all the modules that needs logging (to create a logger hierarchy):

import logging
logger = logging.getLogger(__name__)

And use logger.{debug, info, warning, ...} instead of print, giving users full control over how and the logs are written.

@tomtung
Copy link
Contributor

tomtung commented Oct 11, 2017

Also not sure why we need global variables to prevent layer name collisions, since after all the use of TensorFlow's variable scopes already handles that.

Maybe it's also easier to just pass reuse as a parameter to the constructors of layers, instead of maintaining it as the global state set_keep['name_reuse'], which is almost not respected anywhere (except for TimeDistributedLayer) anyways.

@tomtung tomtung mentioned this issue Oct 11, 2017
@luomai
Copy link
Member

luomai commented Jan 6, 2018

@tomtung @mitar @haiy we are preparing for a PR to replace all the print with logging in the library.

@DEKHTIARJonathan
Copy link
Member

Just to repeat what I proposed in #306

The idea would be to make this output optional (default = True or False). I think there could be different ways to do this.

1. Solution - Create a verbose parameter in the Layer API

Simple and backward compatible, a "verbose" parameter can be added to the Layer Class and influence the behavior of print_params() method.

2. Use the Logging module from TF.

Why should we re-invent the wheel ? Everything is already implemented in Tensorflow.
We can use the logging level already existing in TF.

tf.logging._level_names    ## outputs => {50: 'FATAL', 40: 'ERROR', 30: 'WARN', 20: 'INFO', 10: 'DEBUG'}
tf.logging.get_verbosity() ## outputs => 30 (default value)

tf.logging.set_verbosity(tf.logging.DEBUG)
tf.logging.get_verbosity() ## outputs => 10

We could for instance determine that for logging level <= 20 (INFO & DEBUG), we normally output the Tensorlayer informations, and we don't perform this action for any higher value.

luomai added a commit that referenced this issue Feb 16, 2018
Replace print to logging in other modules (#207)
@luomai luomai closed this as completed Feb 18, 2018
luomai added a commit that referenced this issue Nov 21, 2018
Replace print to logging in other modules (#207)
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

No branches or pull requests

6 participants