btrz-logger
Advanced tools
Comparing version 2.5.1 to 2.5.2
{ | ||
"name": "btrz-logger", | ||
"version": "2.5.1", | ||
"version": "2.5.2", | ||
"description": "A multi-transport logger", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,6 +1,18 @@ | ||
"use strict"; | ||
const assert = require("assert"); | ||
const _ = require("lodash"); | ||
const logentries = require("node-logentries"); | ||
const logCleaner = require("./log-cleaner"); | ||
// We memoize the function that creates connections to Logentries so that we only create one connection to Logentries for each unique | ||
// api token | ||
const cacheKeyResolver = (options) => { | ||
return options.token; | ||
}; | ||
const createLogEntriesLogger = _.memoize((...args) => { | ||
return logentries.logger(...args); | ||
}, cacheKeyResolver); | ||
function stringifyTokens(tokens) { | ||
@@ -22,3 +34,3 @@ return { | ||
options.levels = {access: 0, debug: 1, info: 2, error: 3, fatal: 4}; | ||
this.logger = logentries.logger(options); | ||
this.logger = createLogEntriesLogger(options); | ||
} | ||
@@ -25,0 +37,0 @@ |
@@ -22,3 +22,21 @@ const {expect} = require("chai"); | ||
}); | ||
it("should re-use existing connections to LogEntries when an existing connection was created for the same api token", () => { | ||
const logEntriesLoggerSpy = sandbox.spy(logentries, "logger"); | ||
let logEntriesLogger = new LogEntriesLogger({token: "A"}); | ||
expect(logEntriesLoggerSpy.callCount).to.eql(1); | ||
expect(logEntriesLogger.logger).to.eql(logEntriesLoggerSpy.getCall(0).returnValue); | ||
// Create another instance with the same logentries token. We expect the logentries logger from the first instance to be re-used. | ||
logEntriesLogger = new LogEntriesLogger({token: "A"}); | ||
expect(logEntriesLoggerSpy.callCount).to.eql(1); | ||
expect(logEntriesLogger.logger).to.eql(logEntriesLoggerSpy.getCall(0).returnValue); | ||
// Create another instance with a different logentries token. We expect a new logentries logger to be created. | ||
logEntriesLogger = new LogEntriesLogger({token: "B"}); | ||
expect(logEntriesLoggerSpy.callCount).to.eql(2); | ||
expect(logEntriesLogger.logger).to.eql(logEntriesLoggerSpy.getCall(1).returnValue); | ||
}); | ||
}); | ||
}); |
26619
622