Skip to content

Commit ea580c4

Browse files
committed
Merge pull request #8 from perezd/logging
expose the log function as a module export so that it can be overriden
2 parents 248cad5 + bf519d5 commit ea580c4

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/request.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ if(! ('_object' in (new XHR)))
2424

2525
module.exports = request
2626
request.XMLHttpRequest = XHR
27+
request.log = getLogger()
2728

2829
var DEFAULT_TIMEOUT = 3 * 60 * 1000 // 3 minutes
29-
, LOG = getLogger()
3030

3131
//
3232
// request
@@ -129,7 +129,7 @@ function run_xhr(options) {
129129
er.code = 'ETIMEDOUT'
130130
er.duration = options.timeout
131131

132-
LOG.error('Timeout', { 'id':xhr._id, 'milliseconds':options.timeout })
132+
request.log.error('Timeout', { 'id':xhr._id, 'milliseconds':options.timeout })
133133
return options.callback(er, xhr)
134134
}
135135

@@ -145,12 +145,12 @@ function run_xhr(options) {
145145

146146
function on_state_change(event) {
147147
if(timed_out)
148-
return LOG.debug('Ignoring timed out state change', {'state':xhr.readyState, 'id':xhr.id})
148+
return request.log.debug('Ignoring timed out state change', {'state':xhr.readyState, 'id':xhr.id})
149149

150-
LOG.debug('State change', {'state':xhr.readyState, 'id':xhr.id, 'timed_out':timed_out})
150+
request.log.debug('State change', {'state':xhr.readyState, 'id':xhr.id, 'timed_out':timed_out})
151151

152152
if(xhr.readyState === XHR.OPENED) {
153-
LOG.debug('Request started', {'id':xhr.id})
153+
request.log.debug('Request started', {'id':xhr.id})
154154
for (var key in options.headers)
155155
xhr.setRequestHeader(key, options.headers[key])
156156
}
@@ -175,7 +175,7 @@ function run_xhr(options) {
175175
return
176176

177177
did.response = true
178-
LOG.debug('Got response', {'id':xhr.id, 'status':xhr.status})
178+
request.log.debug('Got response', {'id':xhr.id, 'status':xhr.status})
179179
clearTimeout(xhr.timeoutTimer)
180180
xhr.statusCode = xhr.status // Node request compatibility
181181

@@ -199,7 +199,7 @@ function run_xhr(options) {
199199
return
200200

201201
did.loading = true
202-
LOG.debug('Response body loading', {'id':xhr.id})
202+
request.log.debug('Response body loading', {'id':xhr.id})
203203
// TODO: Maybe simulate "data" events by watching xhr.responseText
204204
}
205205

@@ -208,7 +208,7 @@ function run_xhr(options) {
208208
return
209209

210210
did.end = true
211-
LOG.debug('Request done', {'id':xhr.id})
211+
request.log.debug('Request done', {'id':xhr.id})
212212

213213
xhr.body = xhr.responseText
214214
if(options.json) {

0 commit comments

Comments
 (0)