Merge lp:~veebers/ubuntu-community-testing/adding-logging-for-upstart into lp:ubuntu-community-testing

Proposed by Christopher Lee on 2015-08-18
Status: Merged
Merged at revision: 27
Proposed branch: lp:~veebers/ubuntu-community-testing/adding-logging-for-upstart
Merge into: lp:ubuntu-community-testing
Diff against target: 74 lines (+24/-1)
3 files modified
ubuntu_pt_community/__init__.py (+17/-0)
ubuntu_pt_community/api/v1.py (+3/-1)
ubuntu_pt_community/auth/sso.py (+4/-0)
To merge this branch: bzr merge lp:~veebers/ubuntu-community-testing/adding-logging-for-upstart
Reviewer Review Type Date Requested Status
Ubuntu Testcase Admins 2015-08-18 Pending
Review via email: mp+268282@code.launchpad.net

Commit message

Update logging so that messages appear in the upstart log.

Description of the change

Update logging so that messages appear in the upstart log.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_pt_community/__init__.py'
2--- ubuntu_pt_community/__init__.py 2015-08-04 02:35:03 +0000
3+++ ubuntu_pt_community/__init__.py 2015-08-18 00:56:35 +0000
4@@ -15,11 +15,28 @@
5 # You should have received a copy of the GNU General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7 #
8+import logging
9+import sys
10
11 from ubuntu_pt_community import api
12
13 from flask import Flask
14
15+
16+def setup_logging():
17+ root = logging.getLogger()
18+ root.setLevel(logging.INFO)
19+
20+ ch = logging.StreamHandler(sys.stdout)
21+ formatter = logging.Formatter(
22+ '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
23+ )
24+ ch.setFormatter(formatter)
25+ root.addHandler(ch)
26+
27+
28+setup_logging()
29+
30 app = Flask(__name__)
31
32 api.define_api_routes(app)
33
34=== modified file 'ubuntu_pt_community/api/v1.py'
35--- ubuntu_pt_community/api/v1.py 2015-08-18 00:46:51 +0000
36+++ ubuntu_pt_community/api/v1.py 2015-08-18 00:56:35 +0000
37@@ -62,14 +62,16 @@
38
39 try:
40 upload_json_data = request.files['data'].stream.getvalue()
41+ logger.info('Uploading results to practitest.')
42 upload_results(json.loads(upload_json_data.decode('utf-8')), pt)
43 store_upload_details(request, upload_json_data)
44 except KeyError:
45- print('No files provided.')
46+ logger.error('No files provided.')
47 return 'Uploading successful.'
48
49
50 def store_upload_details(request, json_data):
51+ logger.info('Storing upload details.')
52 # If email address is None, should we continue to store the data?
53 email_address = get_user_email_address(request)
54 if email_address is None:
55
56=== modified file 'ubuntu_pt_community/auth/sso.py'
57--- ubuntu_pt_community/auth/sso.py 2015-08-14 04:45:18 +0000
58+++ ubuntu_pt_community/auth/sso.py 2015-08-18 00:56:35 +0000
59@@ -47,11 +47,15 @@
60 http_method=response.method,
61 authorization=response.headers['Authorization'])
62 except KeyError:
63+ logger.error(
64+ 'Auth Failed: No authorization details found in header'
65+ )
66 raise Unauthorized('No authorization details found.')
67
68 validate_response = requests.post(
69 SSO_BASE_URL + '/requests/validate', json.dumps(data),
70 headers=JSON_HEADERS)
71 if not validate_response.ok:
72+ logger.error('Validation failed against login server.')
73 raise Unauthorized('Validation failed against login server.')
74 return validate_response.json()

Subscribers

People subscribed via source and target branches