@@ -134,79 +134,63 @@ def emit(self, record):
134
134
try :
135
135
136
136
if (record .levelname == "ERROR" or record .levelname == "WARNING" or record .levelname == "CRITICAL" ):
137
-
138
- errorMessage = record .message
139
- fileAndLine = record .pathname + ', line: ' + str (record .lineno )
140
- dateTime = record .asctime
141
- type = record .levelname
142
- engine = record .name
143
-
144
-
145
- #covering warnings/probableCause/traceback missing
146
- traceback = 'No traceback available'
147
- probableCause = ''
148
-
149
- if record .exc_text is not None :
150
- traceback = record .exc_text
151
- splitTraceback = traceback .split ('\n ' )
152
- probableCause = splitTraceback [len (splitTraceback ) - 1 ]
153
-
154
-
155
- #covering retrys
156
- if ("Gave up retrying <" in record .message ):
157
-
158
- for retryError in self .retryErrors :
159
- if (retryError in record .message ):
160
- method = record .message .split ('<' )[1 ].split (' ' )[0 ]
161
- errorMessage = "Error: Gave up retrying " + method + " request - " + retryError
162
- fileAndLine = ''
163
- probableCause = retryError
164
- break
165
-
166
- # Deprecation Warnings
167
- if "ScrapyDeprecationWarning:" in record .message and record .message [0 ] == "/" :
168
- splitString = record .message .split ("ScrapyDeprecationWarning:" )
169
- errorMessage = "ScrapyDeprecationWarning: " + splitString [1 ]
170
- probableCause = splitString [0 ]
171
-
172
-
173
- # "Some Other Error Occurred"
174
- if "Some other error occurred: " in record .message :
175
- splitError = record .message .split (' /' )
176
- cleanError = splitError [0 ].split (">: " )[1 ]
177
- errorMessage = "Some other error occurred: " + cleanError
178
- probableCause = cleanError
179
- traceback = record .message
180
-
181
-
182
- # Convert Urls To Domains in Error Messages
183
- urls = re .findall (r'(https?://[^\s]+)' , errorMessage )
184
- for url in urls :
185
- domain = DomainNormalizer .get_domain (url )
186
- errorMessage = errorMessage .replace (url , domain )
187
-
188
-
189
- if errorMessage in self .log_dict :
190
- self .log_dict [errorMessage ]['count' ] = self .log_dict [errorMessage ]['count' ] + 1
191
- else :
192
- self .log_dict [errorMessage ] = {
193
- 'type' : type ,
194
- 'engine' : engine ,
195
- 'name' : errorMessage ,
196
- 'count' : 1 ,
197
- 'traceback' : traceback ,
198
- 'message' : probableCause ,
199
- 'filepath' : fileAndLine ,
200
- 'dateTime' : dateTime
201
- }
202
-
203
- if (SOPSRequest .HIGH_FREQ_ACC == True ):
204
-
205
- if (errorMessage in self .log_dict_cumulative ):
206
- self .log_dict_cumulative [errorMessage ]['count' ] = self .log_dict_cumulative [errorMessage ]['count' ] + 1
137
+
138
+ if hasattr (record , 'message' ):
139
+ errorMessage = record .message
140
+ fileAndLine = record .pathname + ', line: ' + str (record .lineno )
141
+ dateTime = record .asctime
142
+ type = record .levelname
143
+ engine = record .name
144
+
145
+
146
+ #covering warnings/probableCause/traceback missing
147
+ traceback = 'No traceback available'
148
+ probableCause = ''
149
+
150
+ if record .exc_text is not None :
151
+ traceback = record .exc_text
152
+ splitTraceback = traceback .split ('\n ' )
153
+ probableCause = splitTraceback [len (splitTraceback ) - 1 ]
154
+
155
+
156
+ #covering retrys
157
+ if ("Gave up retrying <" in record .message ):
158
+
159
+ for retryError in self .retryErrors :
160
+ if (retryError in record .message ):
161
+ method = record .message .split ('<' )[1 ].split (' ' )[0 ]
162
+ errorMessage = "Error: Gave up retrying " + method + " request - " + retryError
163
+ fileAndLine = ''
164
+ probableCause = retryError
165
+ break
166
+
167
+ # Deprecation Warnings
168
+ if "ScrapyDeprecationWarning:" in record .message and record .message [0 ] == "/" :
169
+ splitString = record .message .split ("ScrapyDeprecationWarning:" )
170
+ errorMessage = "ScrapyDeprecationWarning: " + splitString [1 ]
171
+ probableCause = splitString [0 ]
172
+
173
+
174
+ # "Some Other Error Occurred"
175
+ if "Some other error occurred: " in record .message :
176
+ splitError = record .message .split (' /' )
177
+ cleanError = splitError [0 ].split (">: " )[1 ]
178
+ errorMessage = "Some other error occurred: " + cleanError
179
+ probableCause = cleanError
180
+ traceback = record .message
181
+
182
+
183
+ # Convert Urls To Domains in Error Messages
184
+ urls = re .findall (r'(https?://[^\s]+)' , errorMessage )
185
+ for url in urls :
186
+ domain = DomainNormalizer .get_domain (url )
187
+ errorMessage = errorMessage .replace (url , domain )
188
+
189
+
190
+ if errorMessage in self .log_dict :
191
+ self .log_dict [errorMessage ]['count' ] = self .log_dict [errorMessage ]['count' ] + 1
207
192
else :
208
-
209
- self .log_dict_cumulative [errorMessage ] = {
193
+ self .log_dict [errorMessage ] = {
210
194
'type' : type ,
211
195
'engine' : engine ,
212
196
'name' : errorMessage ,
@@ -215,7 +199,24 @@ def emit(self, record):
215
199
'message' : probableCause ,
216
200
'filepath' : fileAndLine ,
217
201
'dateTime' : dateTime
218
- }
202
+ }
203
+
204
+ if (SOPSRequest .HIGH_FREQ_ACC == True ):
205
+
206
+ if (errorMessage in self .log_dict_cumulative ):
207
+ self .log_dict_cumulative [errorMessage ]['count' ] = self .log_dict_cumulative [errorMessage ]['count' ] + 1
208
+ else :
209
+
210
+ self .log_dict_cumulative [errorMessage ] = {
211
+ 'type' : type ,
212
+ 'engine' : engine ,
213
+ 'name' : errorMessage ,
214
+ 'count' : 1 ,
215
+ 'traceback' : traceback ,
216
+ 'message' : probableCause ,
217
+ 'filepath' : fileAndLine ,
218
+ 'dateTime' : dateTime
219
+ }
219
220
220
221
except Exception as e :
221
222
logging .info ('Error: Error in error logger' )
0 commit comments