Skip to content

Commit 77e74d5

Browse files
authored
#186810782 : Added logger support (#15)
* added logger * add transaction id in EventModel * change version
1 parent e65347f commit 77e74d5

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

moesifapi/controllers/base_controller.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from ..http.http_request import HttpRequest
1414
from ..http.http_response import HttpResponse
1515
from ..http.requests_client import RequestsClient
16+
import logging
17+
logger = logging.getLogger(__name__)
1618

1719
class BaseController(object):
1820

@@ -36,7 +38,7 @@ def validate_response(self, context):
3638
3739
"""
3840
if (context.response.status_code < 200) or (context.response.status_code > 208): #[200,208] = HTTP OK
39-
print("HTTP Response not ok")
40-
print(context.request.__dict__)
41-
print(context.response.status_code)
41+
logger.error('HTTP Response not ok [response status: ' +
42+
str(context.response.status_code) + ' | header: ' + str(context.response.headers)
43+
+ ' | raw_body: ' + str(context.response.raw_body) + ']')
4244
raise APIException("HTTP response not OK.", context)

moesifapi/models/event_model.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .event_request_model import EventRequestModel
99
from .event_response_model import EventResponseModel
1010
from .base_model import BaseModel
11+
import uuid
1112

1213
class EventModel(BaseModel):
1314

@@ -38,7 +39,8 @@ def __init__(self,
3839
metadata = None,
3940
direction=None,
4041
weight=None,
41-
blocked_by=None):
42+
blocked_by=None,
43+
transaction_id=str(uuid.uuid4())):
4244
"""Constructor for the EventModel class"""
4345

4446
# Initialize members of the class
@@ -52,6 +54,7 @@ def __init__(self,
5254
self.direction = direction
5355
self.weight = weight
5456
self.blocked_by = blocked_by
57+
self.transaction_id = transaction_id
5558

5659
# Create a mapping from Model property names to API property names
5760
self.names = {
@@ -64,7 +67,8 @@ def __init__(self,
6467
"metadata" : "metadata",
6568
"direction": "direction",
6669
"weight": "weight",
67-
"blocked_by": "blocked_by"
70+
"blocked_by": "blocked_by",
71+
"transaction_id": "transaction_id"
6872
}
6973

7074

@@ -96,6 +100,7 @@ def from_dictionary(cls,
96100
direction = dictionary.get("direction")
97101
weight = dictionary.get("weight")
98102
blocked_by = dictionary.get("blocked_by")
103+
transaction_id = dictionary.get("transaction_id")
99104
# Return an object of this model
100105
return cls(request,
101106
response,
@@ -106,4 +111,6 @@ def from_dictionary(cls,
106111
metadata,
107112
direction,
108113
weight,
109-
blocked_by)
114+
blocked_by,
115+
transaction_id
116+
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Versions should comply with PEP440. For a discussion on single-sourcing
2929
# the version across setup.py and the project code, see
3030
# https://packaging.python.org/en/latest/single_source_version.html
31-
version='1.4.1',
31+
version='1.4.2',
3232

3333
description='Moesif API Lib for Python',
3434
long_description=long_description,

0 commit comments

Comments
 (0)