-
Notifications
You must be signed in to change notification settings - Fork 45
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
Replace print into logging #63
Conversation
It should be Or rather a better short log would be: |
the log is empty in preview... what the matter? |
return HttpResponse('<br>'.join(logs)) | ||
|
||
def get_logs(): | ||
with open('./_site/community.log') as log_file: |
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.
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.
This is not how you serve a static file,
read https://docs.djangoproject.com/en/2.0/howto/static-files/
community/decorators.py
Outdated
@@ -0,0 +1,31 @@ | |||
LOGGING_CONFIG = { |
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.
Hey, Django already setup logging for us, Please don't create a new one, just use the one Django already setup.
https://docs.djangoproject.com/en/2.0/topics/logging/
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.
If you need to add more handlers, see https://docs.djangoproject.com/en/2.0/topics/logging/#configuring-logging,
Do it inside settings.py
community/decorators.py
Outdated
} | ||
|
||
|
||
def load_logging_configuration(func): |
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.
Please change the log displayed to not include debug. |
community/settings.py
Outdated
'class': 'logging.FileHandler', | ||
'filename': './_site/community.log', | ||
'formatter': 'standard', | ||
'level': 'NOTSET' |
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.
Set the level to INFO please.
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.
why? we have some log with ERROR
level. like here: https://github.com/seeeturtle/community/blob/af7306e3e886d38d230a50efafa790f7a26221cc/gci/config.py#L33
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.
This specifies the minimum level, and all levels above that are included.
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.
ah, I see. I didn't know well, sorry.
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.
And squash your commits.
gci/client.py
Outdated
@@ -18,14 +18,12 @@ | |||
|
|||
client = gciclient.GCIAPIClient( | |||
auth_token='xxxxxxxxxxxxxx', | |||
url_prefix='https://codein.withgoogle.com', | |||
debug=False) | |||
url_prefix='https://codein.withgoogle.com') |
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.
this is not the problem. this is a docstring. please revert this bit.
gci/client.py
Outdated
@@ -49,21 +47,13 @@ class GCIAPIClient(object): | |||
""" | |||
|
|||
def __init__(self, auth_token=None, | |||
url_prefix='https://codein.withgoogle.com/', | |||
debug=False): |
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.
revert this please. We still need debug support, just not enabled by default
gci/client.py
Outdated
self.url_prefix = urlparse.urljoin(url_prefix, 'api/program/current/') | ||
self.headers = { | ||
'Authorization': 'Bearer %s' % auth_token, | ||
'Content-Type': 'application/json', | ||
} | ||
|
||
if debug: |
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.
please revert this. debug is not enabled. And is not enabled at https://github.com/coala/community/blob/master/gci/students.py#L30
'handlers': { | ||
'communityHandler': { | ||
'class': 'logging.FileHandler', | ||
'filename': './_site/community.log', |
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.
Hey, put this inside the static folder.
https://docs.djangoproject.com/en/2.0/howto/static-files/
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.
this isnt a pre-existing static file. It has to go in _site
gci/students.py
Outdated
@@ -19,6 +20,7 @@ | |||
'deadline', | |||
) | |||
|
|||
|
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.
undo this unrelated change
gci/views.py
Outdated
import requests | ||
|
||
from .students import get_linked_students | ||
from .gitorg import get_logo | ||
from .task import get_tasks | ||
|
||
|
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.
undo this unrelated change
log/view_log.py
Outdated
def get_logs(): | ||
with open('./_site/community.log') as log_file: | ||
for line in log_file: | ||
if 'DEBUG' not in line: |
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.
no this is not how you filter the log. logging
and django have official mechanisms for filtering the log.
We need things like access tokens to be never stored anywhere, at all. Leaving them lying around in files is begging for leaks to occur again due to mistakes.
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.
ok. I'll follow the official mechanisms
gci/config.py
Outdated
@@ -1,5 +1,7 @@ | |||
import ruamel.yaml | |||
import os | |||
import logging | |||
|
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.
this extra blank line isnt desirable.
community/settings.py
Outdated
@@ -11,6 +11,7 @@ | |||
""" | |||
|
|||
import os | |||
from .filters import NoDebugFilter |
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.
add a blank line after system libraries, before local imports.
gci/config.py
Outdated
@@ -27,6 +29,7 @@ def get_api_key(name): | |||
api_key = api_key_file.readline().strip() | |||
return api_key | |||
except IOError: | |||
logger.error('Please put your %s API key at %s.' % (name, filename)) |
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.
as a general rule, do not log before an exception.
An exception is telling the caller there was a problem, and the caller then has to decide what to do with the exception.
The caller may already know about this type of exception, and decide to ignore it because they do not consider it to be an error.
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.
ok
gci/config.py
Outdated
@@ -15,6 +16,7 @@ class TokenMissing(KeyError): | |||
|
|||
|
|||
def get_api_key(name): | |||
logger = logging.getLogger(__name__ + 'get_api_key') |
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.
logging names are dot separated. so this should be __name__ + '.get_api_key'
. The same applies everywhere in your patch.
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.
ok
gci/gitorg.py
Outdated
@@ -13,11 +14,12 @@ | |||
class GitOrg(): | |||
|
|||
def __init__(self, name): | |||
logger = logging.getLogger(__name__ + '__init__') |
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.
you need to add dots to all of the loggers.
And please rebase & squash before asking for reviews.
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.
sorry, I missed it.
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.
done @jayvdb
This will replace print statements with standard logging. It store logs in _site/community.log Closes coala#9
ack fec438a |
This will replace print to standard logging.
It store logs in _site/community.log
Closes #9