-
Notifications
You must be signed in to change notification settings - Fork 38
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
092545e
953d1ce
138da74
04fbdbb
34ce206
c611197
cea7db2
63e3d4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
from __future__ import print_function | ||
|
||
import os.path | ||
import socket | ||
import threading | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
"""Nengo GUI backend implementation.""" | ||
|
||
from __future__ import print_function | ||
|
||
import hashlib | ||
import json | ||
import logging | ||
|
@@ -252,7 +250,7 @@ def _handle_ws_msg(self, component, msg): | |
component.message(msg.data) | ||
return True | ||
except: | ||
logging.exception('Error processing: %s', repr(msg.data)) | ||
logger.exception('Error processing: %s', repr(msg.data)) | ||
|
||
def _handle_config_msg(self, component, msg): | ||
cfg = json.loads(msg.data[7:]) | ||
|
@@ -295,7 +293,7 @@ def get_session(self): | |
return session | ||
|
||
def log_message(self, format, *args): | ||
logger.info(format, *args) | ||
logger.debug(format, *args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
|
||
class ModelContext(object): | ||
|
@@ -399,6 +397,6 @@ def remove_page(self, page): | |
time.sleep(self.settings.auto_shutdown) | ||
earliest_shutdown = self._last_access + self.settings.auto_shutdown | ||
if earliest_shutdown < time.time() and len(self.pages) <= 0: | ||
logging.info( | ||
logger.info( | ||
"No connections remaining to the nengo_gui server.") | ||
self.shutdown() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import argparse | ||
import logging | ||
import os.path | ||
import sys | ||
import threading | ||
import webbrowser | ||
|
||
|
@@ -10,9 +11,13 @@ | |
from nengo_gui.password import gensalt, hashpw, prompt_pw | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
def old_main(): | ||
print("'nengo_gui' has been renamed to 'nengo'.") | ||
print("Please run 'nengo' in the future to avoid this message!\n") | ||
print("'nengo_gui' has been renamed to 'nengo'.", file=sys.stderr) | ||
print("Please run 'nengo' in the future to avoid this message!\n", | ||
file=sys.stderr) | ||
main() | ||
|
||
|
||
|
@@ -46,9 +51,9 @@ def main(): | |
args = parser.parse_args() | ||
|
||
if args.debug: | ||
logging.basicConfig(level=logging.DEBUG) | ||
logging.basicConfig(format='%(message)s', level=logging.DEBUG) | ||
else: | ||
logging.basicConfig() | ||
logging.basicConfig(format='%(message)s', level=logging.INFO) | ||
|
||
if args.password: | ||
if args.password is True: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
from __future__ import print_function | ||
|
||
import os | ||
import time | ||
|
||
|
There was a problem hiding this comment.
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 stayprint
s or should be converted tosys.stdout.write
because this output is part of direct user interaction and should never be redirected to a log file for example.There was a problem hiding this comment.
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
print
s in this function should stayprint
s too. Though it is not as clear cut for those.