Code coverage report for monolog\lib\handler\CouchDBHandler.js

Statements: 93.1% (54 / 58)      Branches: 55% (11 / 20)      Functions: 81.82% (9 / 11)      Lines: 93.88% (46 / 49)      Ignored: none     

All files » monolog\lib\handler\ » CouchDBHandler.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102    1     1   1   1   1 1 1 1 2 2 8 8     1     1   1   1 1   1           1   1 1 1   1 1   1 1 1     1 1 1                     1     1 1   1     1 1 1 1 1 1       1     1     1 1     1       1          
// Generated by CoffeeScript 1.6.3
"use strict";
var AbstractProcessingHandler, CouchDBHandler, JSONFormatter, http, mixin, noop,
  __slice = [].slice,
  __hasProp = {}.hasOwnProperty,
  __extends = function(child, parent) { for (var key in parent) { Eif (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
 
http = require('http');
 
noop = function() {};
 
mixin = function() {
  var object, objects, property, target, _i, _len;
  target = arguments[0], objects = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
  for (_i = 0, _len = objects.length; _i < _len; _i++) {
    object = objects[_i];
    for (property in object) {
      Iif (!__hasProp.call(object, property)) continue;
      target[property] = object[property];
    }
  }
  return target;
};
 
AbstractProcessingHandler = require('./AbstractProcessingHandler');
 
JSONFormatter = require('../formatter/JSONFormatter');
 
CouchDBHandler = (function(_super) {
  __extends(CouchDBHandler, _super);
 
  CouchDBHandler.prototype.defaultOptions = {
    host: 'localhost',
    dbname: 'logger',
    port: 5984
  };
 
  CouchDBHandler.prototype.request = http.request;
 
  function CouchDBHandler(options, level, bubble) {
    Eif (level == null) {
      level = 100;
    }
    Eif (bubble == null) {
      bubble = true;
    }
    this.options = mixin({}, this.defaultOptions, options);
    CouchDBHandler.__super__.constructor.call(this, level, bubble);
    this.formatter = new JSONFormatter;
  }
 
  CouchDBHandler.prototype.getStreamOptions = function() {
    Eif (this._streamOptions == null) {
      this._streamOptions = {
        hostname: this.options.host,
        method: "POST",
        port: this.options.port ? this.options.port : 80,
        path: "/" + this.options.dbname,
        auth: this.options.username !== void 0 && this.options.password !== void 0 ? "" + this.options.username + ":" + this.options.password : "",
        headers: {
          "content-type": "application/json"
        }
      };
    }
    return this._streamOptions;
  };
 
  CouchDBHandler.prototype.write = function(record, cb) {
    var r,
      _this = this;
    Iif (cb == null) {
      cb = noop;
    }
    r = this.request(this.getStreamOptions(), function(res) {
      res.setEncoding('utf8');
      return res.on('data', function(data) {
        var ignore;
        try {
          data = JSON.parse(data);
        } catch (_error) {
          ignore = _error;
        }
        return cb(void 0, data, record, _this);
      });
    });
    r.on("error", function(err, res) {
      return cb(err, res, record, _this);
    });
    r.end(JSON.stringify(record));
    return this.bubble;
  };
 
  return CouchDBHandler;
 
})(AbstractProcessingHandler);
 
module.exports = CouchDBHandler;
 
/*
//@ sourceMappingURL=CouchDBHandler.map
*/