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

Logging instead of print #860

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

astoeckel
Copy link
Contributor

@astoeckel astoeckel commented Feb 7, 2017

This pull request fixes #290. All modules fetch a module-specific logger object which is then used to log messages previously printed with print, or logging. without a logger object.

This patchset should not significantly change the output of nengo_gui visible to the user. A future improvement would be a nice formater, which may print the log severity and other information. Note that all messages are now written to stderr instead of stdout.

Note that this patch set touches various places all over the code, it should thus be reviewed thoroughly.

Things which need to be checked before merging this pull request:

  • Were the log severities chosen correctly?
  • Does lowering the default log level have any unwanted side-effects?
  • Can the calls to the warnings-module in ipython.py be safely replaced by calls to logging? My guess was no, so I didn't change anything there.

Reason for the change of the format string is not to change the
output on the command line. A nice formater may be desirable in
the long run.
These log messages are not that important to the average user. Since
the default log level has been set to "info", the log level of these
messages has to be adapted in order to hide them from the user.
Copy link
Collaborator

@jgosmann jgosmann left a comment

Choose a reason for hiding this comment

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

nengo_gui/gui.py Outdated
else:
print("No confirmation received. Resuming...")
Copy link
Collaborator

Choose a reason for hiding this comment

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

These last two print statements should either stay prints or should be converted to sys.stdout.write because this output is part of direct user interaction and should never be redirected to a log file for example.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I might argue that the other prints in this function should stay prints too. Though it is not as clear cut for those.

nengo_gui/gui.py Outdated

self.server.wait_for_shutdown(0.05)
n_zombie = sum(thread.is_alive()
for thread, _ in self.server.requests)
if n_zombie > 0:
print("%d zombie threads will close abruptly" % n_zombie)
logger.warning("%d zombie threads will close abruptly",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd probably make this a debug message. It isn't really relevant to the user.

def old_main():
print("'nengo_gui' has been renamed to 'nengo'.")
print("Please run 'nengo' in the future to avoid this message!\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should always be visible to the user and not end up in some log file. Thus, it should stay a print or even better go to sys.stderr.

@@ -27,4 +31,4 @@ def prompt_pw():
p1 = getpass("Enter password: ")
if p0 == p1:
return p0
print("Passwords do not match. Please try again.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is also code with direct user interaction via stdin and stdout, thus it should stay a print.

@@ -295,7 +295,7 @@ def get_session(self):
return session

def log_message(self, format, *args):
logger.info(format, *args)
logger.debug(format, *args)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are “these” log messages? It seems that this function isn't called in normal operation. Maybe in some specific error cases? But if it is error cases a higher log level might be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is called from the web server base class and is called once for each incoming request.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right, for some reason those messages did not appear on my Macbook (potentially I was running the wrong version of Nengo GUI). I agree that the debug log level makes more sense.

@jgosmann jgosmann self-assigned this Feb 8, 2017
@jgosmann jgosmann removed their assignment Feb 8, 2017
@jgosmann
Copy link
Collaborator

jgosmann commented Feb 8, 2017

Added a commit to change things back to prints where appropriate. LGTM now. 🍰

It seems safe to me to replace this `warns` call with a logging call
and it makes things consistent with the other logging call for error
output. It seems to also give a nicer output in the notebook.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Use logging instead of print statements
2 participants