               else
                 errors.push new models.Error err1, err1
             callback errors
-            log "error", {paymentMethodId, operation, data: result.errors}
+            logHelper "error", {paymentMethodId, operation, data: result.errors}
           else
             # Find next page's URL if necessary
             nextUrl = parseNextUrl res  if res.headers.link
             callback null, result, nextUrl
-            log "info", {paymentMethodId, operation, data: JSON.stringify(result)}
+            logHelper "info", {paymentMethodId, operation, data: JSON.stringify(result)}
 
     req.on 'error', (e)->
       callback [new models.Error 'connection', 'Unable to connect to payment backend.']

      ]
    }

    log = (type, {paymentMethodId, data, operation}) ->
      if @loggedRequests.test operation
        paymentMethodInfo = if paymentMethodId then "PaymentMethodId: #{paymentMethodId}\n" else ""
        logger[type] "\n#{paymentMethodInfo}Operation: #{operation} \nData: #{data}"  

      options.headers['Content-Type'] = 'application/xml; charset=UTF-8'

    console.time 'Recurly API request'
    logHelper "info", {paymentMethodId, operation, data}

    req = https.request options, (res)->
      res.setEncoding 'utf8'
