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

Replace print into logging #63

Merged
merged 1 commit into from
Dec 20, 2017
Merged

Replace print into logging #63

merged 1 commit into from
Dec 20, 2017

Conversation

seeeturtle
Copy link
Member

This will replace print to standard logging.
It store logs in _site/community.log

Closes #9

@manu-chroma
Copy link

manu-chroma commented Dec 18, 2017

It should be Replace print with (in your commit)

Or rather a better short log would be: Use logging in place of print statements

@seeeturtle
Copy link
Member Author

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:
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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/

@@ -0,0 +1,31 @@
LOGGING_CONFIG = {
Copy link
Member

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/

Copy link
Member

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

}


def load_logging_configuration(func):
Copy link
Member

Choose a reason for hiding this comment

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

@jayvdb
Copy link
Member

jayvdb commented Dec 20, 2017

Please change the log displayed to not include debug.
And squash your commits.

'class': 'logging.FileHandler',
'filename': './_site/community.log',
'formatter': 'standard',
'level': 'NOTSET'
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@jayvdb jayvdb left a 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')
Copy link
Member

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):
Copy link
Member

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:
Copy link
Member

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',
Copy link
Member

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/

Copy link
Member

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',
)


Copy link
Member

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


Copy link
Member

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:
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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.

@@ -11,6 +11,7 @@
"""

import os
from .filters import NoDebugFilter
Copy link
Member

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))
Copy link
Member

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.

Copy link
Member Author

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')
Copy link
Member

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.

Copy link
Member Author

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__')
Copy link
Member

@jayvdb jayvdb Dec 20, 2017

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, I missed it.

Copy link
Member Author

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
@jayvdb
Copy link
Member

jayvdb commented Dec 20, 2017

ack fec438a

@jayvdb jayvdb merged commit fec438a into coala:master Dec 20, 2017
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.

None yet

5 participants