@@ -93,8 +93,8 @@ def __init__(self, api_key, context_app_version="1.0", context_deployment_stage=
93
93
self ._events_api = EventsApi (ApiClient (Configuration ().host ))
94
94
# Should get the default url. Also try Configuration().host
95
95
96
- def create_new_app_event (self , log_level = "error" , classification = "Issue" , event_type = None ,
97
- event_message = None , exc_info = None ):
96
+ def create_new_app_event (self , log_level = "error" , classification = "Issue" , event_type = "unknown" ,
97
+ event_message = "unknown" , exc_info = False ):
98
98
"""
99
99
Creates a new AppEvent instance.
100
100
:param log_level: Strng representation on the level of the Error.
@@ -108,16 +108,19 @@ def create_new_app_event(self, log_level="error", classification="Issue", event_
108
108
:return: AppEvent instance with exc_info parsed depending on the above flags.
109
109
"""
110
110
try :
111
- if exc_info is None :
111
+ if exc_info is True or exc_info is None :
112
112
exc_info = sys .exc_info ()
113
+ if not any (exc_info ):
114
+ exc_info = False
115
+
113
116
if exc_info is not False :
114
117
if not TrakerrUtils .is_exc_info_tuple (exc_info ):
115
118
raise TypeError (
116
119
"exc_info is expected an exc_info info tuple or False." )
117
120
errtype , value = exc_info [:2 ]
118
- if event_type is None :
121
+ if event_type is None or event_type == "unknown" :
119
122
event_type = TrakerrUtils .format_error_name (errtype )
120
- if event_message is None :
123
+ if event_message is None or event_message == "unknown" :
121
124
event_message = str (value )
122
125
123
126
if (not isinstance (log_level , string_types )
@@ -161,36 +164,41 @@ def send_event(self, app_event):
161
164
self .fill_defaults (app_event )
162
165
self ._events_api .events_post (app_event )
163
166
164
- def send_event_async (self , app_event ):
167
+ def send_event_async (self , app_event , call_back = None ):
165
168
"""
166
169
Asyncronously sends the given AppEvent instance to trakerr.
167
170
:param app_event: AppEvent instance to send to trakerr.
171
+ :param call_back: Callback method for the async call.
172
+ defaults to module level async_callback.
168
173
"""
169
174
170
175
if not isinstance (app_event , AppEvent ):
171
176
raise TypeError ("Argument is expected of class AppEvent." )
172
177
178
+ if call_back is None :
179
+ call_back = async_callback
180
+
173
181
self .fill_defaults (app_event )
174
182
self ._events_api .events_post_with_http_info (
175
- app_event , callback = async_callback )
183
+ app_event , callback = call_back )
176
184
177
- def log (self , arg_dict , log_level = "error" , classification = "issue" , exc_info = None ):
185
+ def log (self , arg_dict , log_level = "error" , classification = "issue" , exc_info = True ):
178
186
"""
179
187
Creates an AppEvent and sends it with the default values to all fields.
180
188
Allows the caller to pass in user and session as added information to log,
181
189
to file the error under.
182
190
:param arg_dict: Dictionary with any of these key value pairs assigned to a string:
183
- errname, errmessage, user, session. You can leave any pair out that you don't need.
184
- To construct with pure default values,pass in an empty dictionary.
185
- If you are getting the Stacktrace errname and message will be filled with
186
- the values from Stacktrace. Otherwise, both errname and errmessage will be unknown.
191
+ errname, errmessage, user, session. You can leave any pair out that you don't need.
192
+ To construct with pure default values,pass in an empty dictionary.
193
+ If you are getting the Stacktrace errname and message will be filled with
194
+ the values from Stacktrace. Otherwise, both errname and errmessage will be unknown.
187
195
:param log_level: String representation on the level of the Error.
188
- Can be 'debug', 'info', 'warning', 'error', 'fatal', defaults to 'error'.
196
+ Can be 'debug', 'info', 'warning', 'error', 'fatal', defaults to 'error'.
189
197
:param classification: Optional extra string descriptor to clarify the error.
190
- (IE: log_level is fatal and classification may be 'hard lock' or 'Network error')
198
+ (IE: log_level is fatal and classification may be 'hard lock' or 'Network error')
191
199
:param exc_info: exc_info tuple to parse.
192
- Default None to generate a exc_info tuple from the current stacktrace.
193
- Pass False to not generate an exc_info tuple.
200
+ Default None to generate a exc_info tuple from the current stacktrace.
201
+ Pass False to not generate an exc_info tuple.
194
202
"""
195
203
excevent = self .create_new_app_event (log_level ,
196
204
classification , arg_dict .get (
@@ -206,7 +214,7 @@ def fill_defaults(self, app_event):
206
214
fill out the the event with the instance defaults.
207
215
:param app_event: The app event to fill parameters out.
208
216
:return: The fully filled out AppEvent object,
209
- while also filling out the instance passed in.
217
+ while also filling out the instance passed in.
210
218
"""
211
219
212
220
if not isinstance (app_event , AppEvent ):
@@ -425,4 +433,4 @@ def async_callback(response):
425
433
:param response: message returned after the async call is completed.
426
434
"""
427
435
428
- pprint .pprint (str (response ), sys .stderr )
436
+ # pprint.pprint(str(response), sys.stderr)
0 commit comments