Merge lp:~joetalbott/adt-cloud-service/add_logging_extras into lp:adt-cloud-service

Proposed by Joe Talbott
Status: Merged
Approved by: Thomi Richards
Approved revision: 25
Merged at revision: 23
Proposed branch: lp:~joetalbott/adt-cloud-service/add_logging_extras
Merge into: lp:adt-cloud-service
Diff against target: 105 lines (+49/-4)
3 files modified
adt_cloud_service/constants.py (+36/-0)
adt_cloud_service/queue.py (+9/-3)
adt_cloud_service/v1.py (+4/-1)
To merge this branch: bzr merge lp:~joetalbott/adt-cloud-service/add_logging_extras
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
Review via email: mp+256359@code.launchpad.net

Commit message

Add extra service info to logging.

Description of the change

Add extra service info to logging.

To post a comment you must log in.
24. By Joe Talbott

Move 'logging_extra' to the constants module.

25. By Joe Talbott

Fix extra data.

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'adt_cloud_service/constants.py'
2--- adt_cloud_service/constants.py 1970-01-01 00:00:00 +0000
3+++ adt_cloud_service/constants.py 2015-04-15 17:21:13 +0000
4@@ -0,0 +1,36 @@
5+# adt-cloud-service
6+# Copyright (C) 2015 Canonical
7+#
8+# This program is free software: you can redistribute it and/or modify
9+# it under the terms of the GNU General Public License as published by
10+# the Free Software Foundation, either version 3 of the License, or
11+# (at your option) any later version.
12+#
13+# This program is distributed in the hope that it will be useful,
14+# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+# GNU General Public License for more details.
17+#
18+# You should have received a copy of the GNU General Public License
19+# along with this program. If not, see <http://www.gnu.org/licenses/>.
20+#
21+
22+import socket
23+
24+"""Constants for this service."""
25+
26+
27+API_VERSION = "v1"
28+
29+SOLUTION_NAME = "proposed-migration"
30+
31+SERVICE_NAME = "adt-cloud-service"
32+
33+HOSTNAME = socket.gethostname()
34+
35+
36+logging_extra = {
37+ 'solution': SOLUTION_NAME,
38+ 'service': SERVICE_NAME,
39+ 'hostname': HOSTNAME,
40+}
41
42=== modified file 'adt_cloud_service/queue.py'
43--- adt_cloud_service/queue.py 2015-03-19 22:00:45 +0000
44+++ adt_cloud_service/queue.py 2015-04-15 17:21:13 +0000
45@@ -24,6 +24,8 @@
46 import logging
47 logger = logging.getLogger(__name__)
48
49+from adt_cloud_service.constants import logging_extra
50+
51
52 class RabbitQueuer(object):
53 """A class that can send things to the rabbit queue. An instance of this
54@@ -62,6 +64,8 @@
55 declare = [self.adt_exchange, queue]
56
57 payload_copy['request_id'] = uuid()
58+ extra = logging_extra.copy()
59+ extra.update(payload_copy)
60
61 with producers[self.connection].acquire(block=True) as producer:
62
63@@ -70,8 +74,10 @@
64 # the exception should be registerred with flask, so we
65 # automatically return something nice and RESTful to the user
66 # see: adt_cloud_service.errors.
67- logger.error('Error: %r', exc, exc_info=1)
68- logger.info('Retry in %s seconds.', interval)
69+ logger.error('Error: %r', exc, exc_info=1,
70+ extra=extra)
71+ logger.info('Retry in %s seconds.', interval,
72+ extra=extra)
73
74 publish = self.connection.ensure(
75 producer, producer.publish,
76@@ -81,5 +87,5 @@
77 exchange=self.adt_exchange,
78 routing_key=routing_key,
79 declare=declare)
80- logger.info("Submitted payload %r", payload_copy, extra=payload_copy)
81+ logger.info("Submitted payload %r", payload_copy, extra=extra)
82 return payload_copy['request_id']
83
84=== modified file 'adt_cloud_service/v1.py'
85--- adt_cloud_service/v1.py 2015-04-14 22:23:27 +0000
86+++ adt_cloud_service/v1.py 2015-04-15 17:21:13 +0000
87@@ -24,6 +24,8 @@
88
89 from adt_cloud_service.errors import MissingRequestParameters
90
91+from adt_cloud_service.constants import logging_extra
92+
93 logger = logging.getLogger(__name__)
94
95
96@@ -37,7 +39,8 @@
97 missing = required_keys.difference(set(request.form.keys()))
98 if missing:
99 logger.error("Got request %r with missing keys %r",
100- dict(request.form), missing)
101+ dict(request.form), missing,
102+ extra=logging_extra)
103 raise MissingRequestParameters(missing)
104
105 rabbit_request = dict()

Subscribers

People subscribed via source and target branches