UNPKG

monolog

Version:

Log with Monolog

102 lines (86 loc) 2.95 kB
// 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) { if (__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) { if (!__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) { if (level == null) { level = 100; } if (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() { if (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; if (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 */