From 4968aeed2484b176e4e3022c594d1f3b53d59ec4 Mon Sep 17 00:00:00 2001 From: "Frederic G. MARAND" Date: Thu, 6 Sep 2018 17:39:45 +0200 Subject: [PATCH] Issue #63: Removed useless SenderBase. Failing testProcessors(). - Generic refactoring to clean up import/export formats. --- CHANGELOG.md | 4 +- __tests__/unit/contextSourcingTest.ts | 75 ++++++------ __tests__/unit/logContextTest.ts | 61 +++++----- __tests__/unit/mongodbSenderTest.ts | 36 +++--- __tests__/unit/serializationTest.ts | 2 +- __tests__/unit/serverLoggerTest.ts | 121 +++++++++++++------- __tests__/unit/strategyTest.ts | 11 +- __tests__/unit/test.ts | 2 +- __tests__/unit/types.ts | 19 ++- jest.config.js | 5 - lib/IContext.d.ts | 75 +++++++++--- lib/IContext.js | 20 ++-- lib/IContext.js.map | 2 +- lib/LogLevel.d.ts | 3 +- lib/LogLevel.js | 3 +- lib/LogLevel.js.map | 2 +- lib/Loggers/ClientLogger.d.ts | 8 +- lib/Loggers/ClientLogger.js | 6 +- lib/Loggers/ClientLogger.js.map | 2 +- lib/Loggers/ILogger.d.ts | 4 +- lib/Loggers/Logger.d.ts | 10 +- lib/Loggers/Logger.js | 22 ++-- lib/Loggers/Logger.js.map | 2 +- lib/Loggers/ServerLogger.d.ts | 4 +- lib/Loggers/ServerLogger.js | 8 +- lib/Loggers/ServerLogger.js.map | 2 +- lib/Loggers/index.d.ts | 29 ++--- lib/Loggers/index.js | 59 +++++----- lib/Loggers/index.js.map | 2 +- lib/Processors/BrowserProcessor.d.ts | 25 ++-- lib/Processors/BrowserProcessor.js | 15 +-- lib/Processors/BrowserProcessor.js.map | 2 +- lib/Processors/MeteorUserProcessor.d.ts | 108 +++++++++-------- lib/Processors/MeteorUserProcessor.js | 22 ++-- lib/Processors/MeteorUserProcessor.js.map | 2 +- lib/Processors/ProcessorBase.d.ts | 13 +-- lib/Processors/ProcessorBase.js | 8 +- lib/Processors/ProcessorBase.js.map | 2 +- lib/Processors/RoutingProcessor.d.ts | 34 +++--- lib/Processors/RoutingProcessor.js | 17 ++- lib/Processors/RoutingProcessor.js.map | 2 +- lib/Senders/ConsoleSender.d.ts | 17 ++- lib/Senders/ConsoleSender.js | 33 ++---- lib/Senders/ConsoleSender.js.map | 2 +- lib/Senders/ISender.d.ts | 3 +- lib/Senders/MeteorClientHttpSender.d.ts | 30 ++--- lib/Senders/MeteorClientHttpSender.js | 37 ++---- lib/Senders/MeteorClientHttpSender.js.map | 2 +- lib/Senders/MeteorClientMethodSender.d.ts | 16 ++- lib/Senders/MeteorClientMethodSender.js | 37 +----- lib/Senders/MeteorClientMethodSender.js.map | 2 +- lib/Senders/MongodbSender.d.ts | 28 +++-- lib/Senders/MongodbSender.js | 44 ++----- lib/Senders/MongodbSender.js.map | 2 +- lib/Senders/NullSender.d.ts | 19 ++- lib/Senders/NullSender.js | 36 ++---- lib/Senders/NullSender.js.map | 2 +- lib/Senders/SenderBase.d.ts | 6 +- lib/Senders/SenderBase.js | 3 +- lib/Senders/SenderBase.js.map | 2 +- lib/Senders/SyslogSender.d.ts | 102 ++++++++++------- lib/Senders/SyslogSender.js | 65 ++++------- lib/Senders/SyslogSender.js.map | 2 +- lib/Senders/TeeSender.d.ts | 25 ++-- lib/Senders/TeeSender.js | 33 ++---- lib/Senders/TeeSender.js.map | 2 +- lib/Strategies/IStrategy.d.ts | 3 +- lib/Strategies/LeveledStrategy.d.ts | 42 ++++--- lib/Strategies/LeveledStrategy.js | 27 ++--- lib/Strategies/LeveledStrategy.js.map | 2 +- lib/Strategies/StrategyBase.d.ts | 20 ++-- lib/Strategies/StrategyBase.js | 21 ++-- lib/Strategies/StrategyBase.js.map | 2 +- lib/Strategies/TrivialStrategy.d.ts | 20 ++-- lib/Strategies/TrivialStrategy.js | 15 +-- lib/Strategies/TrivialStrategy.js.map | 2 +- src/IContext.ts | 88 ++++++++++---- src/LogLevel.ts | 3 +- src/Loggers/ClientLogger.ts | 6 +- src/Loggers/ILogger.ts | 4 +- src/Loggers/Logger.ts | 32 +++--- src/Loggers/ServerLogger.ts | 22 ++-- src/Loggers/index.ts | 46 +++++--- src/Processors/BrowserProcessor.ts | 6 +- src/Processors/IProcessor.ts | 2 +- src/Processors/MeteorUserProcessor.ts | 14 ++- src/Processors/ProcessorBase.ts | 8 +- src/Processors/RoutingProcessor.ts | 10 +- src/Senders/ConsoleSender.ts | 17 ++- src/Senders/ISender.ts | 3 +- src/Senders/MeteorClientHttpSender.ts | 13 +-- src/Senders/MeteorClientMethodSender.ts | 20 ++-- src/Senders/MongodbSender.ts | 35 +++--- src/Senders/NullSender.ts | 21 ++-- src/Senders/SenderBase.ts | 6 +- src/Senders/SyslogSender.ts | 35 +++--- src/Senders/TeeSender.ts | 19 ++- src/Strategies/IStrategy.ts | 3 +- src/Strategies/LeveledStrategy.ts | 23 ++-- src/Strategies/StrategyBase.ts | 14 ++- src/Strategies/TrivialStrategy.ts | 10 +- 101 files changed, 1055 insertions(+), 958 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81ffb4a..513c42d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,7 +59,7 @@ ### 0.1.10 / 0.1.9 -* MongoDbSender can now take an existing collection instead of just a name +* MongodbSender can now take an existing collection instead of just a name * Allow logging client request headers * New TrivialStrategy for simple configurations * New documentation site on [https://fgm.github.io/filog](https://fgm.github.io/filog) @@ -97,7 +97,7 @@ * New Syslog sender using modern-syslog * Fixed server-side double escaping in message strings -* Improved collection handling in MongoDbSender +* Improved collection handling in MongodbSender ### 0.1.1 diff --git a/__tests__/unit/contextSourcingTest.ts b/__tests__/unit/contextSourcingTest.ts index 8638f93..9144709 100644 --- a/__tests__/unit/contextSourcingTest.ts +++ b/__tests__/unit/contextSourcingTest.ts @@ -1,11 +1,10 @@ import { - DETAILS_KEY, - HOST_KEY, - IContext, + KEY_DETAILS, + KEY_HOST, + IContext, IDetails, ITimestamps, - ITimestampsHash, - SOURCE_KEY, - TS_KEY, + KEY_SOURCE, + KEY_TS, } from "../../src/IContext"; import { ClientLogger } from "../../src/Loggers/ClientLogger"; import {ILogger} from "../../src/Loggers/ILogger"; @@ -35,8 +34,8 @@ function testContextSourcing(): void { const side = "client"; // Const objects are not immutable: catch details being overwritten. - const details = { a: "A" }; - const expectedDetails = { ...details }; + const details: IDetails = { a: "A" }; + const expectedDetails: IDetails = { ...details }; const t1: number = +new Date(); cl.log(level, message, details); @@ -44,10 +43,10 @@ function testContextSourcing(): void { const expected = { context: { - [DETAILS_KEY]: expectedDetails, - // HOST_KEY: not on client contexts. - [SOURCE_KEY]: side, - // TS_KEY: Cannot test content just with toMatchObject. + [KEY_DETAILS]: expectedDetails, + // KEY_HOST: not on client contexts. + [KEY_SOURCE]: side, + // KEY_TS: Cannot test content just with toMatchObject. }, level, message, @@ -55,15 +54,15 @@ function testContextSourcing(): void { expect(t2).toBeGreaterThanOrEqual(t1); const result = sender.result; expect(typeof result).toBe("object"); - expect(result).not.toHaveProperty(HOST_KEY); + expect(result).not.toHaveProperty(KEY_HOST); expect(result).toMatchObject(expected); const actualContext = result.context; // No side properties without processors. expect(actualContext).not.toHaveProperty(side); - expect(actualContext).toHaveProperty(TS_KEY); - const ts: ITimestampsHash = actualContext[TS_KEY]; + expect(actualContext).toHaveProperty(KEY_TS); + const ts: ITimestamps = actualContext[KEY_TS]; expect(typeof ts).toBe("object"); expect(ts).toHaveProperty(side); expect(ts[side]).toHaveProperty("log"); @@ -82,8 +81,8 @@ function testContextSourcing(): void { const side = "server"; // Const objects are not immutable: catch details being overwritten. - const details = { a: "A" }; - const expectedDetails = { ...details }; + const details: IDetails = { a: "A" }; + const expectedDetails: IDetails = { ...details }; const t1: number = +new Date(); sl.log(level, message, details); @@ -91,10 +90,10 @@ function testContextSourcing(): void { const expected = { context: { - [DETAILS_KEY]: expectedDetails, - [HOST_KEY]: host, - [SOURCE_KEY]: side, - // TS_KEY: Cannot test content just with toMatchObject. + [KEY_DETAILS]: expectedDetails, + [KEY_HOST]: host, + [KEY_SOURCE]: side, + // KEY_TS: Cannot test content just with toMatchObject. }, level, message, @@ -105,8 +104,8 @@ function testContextSourcing(): void { expect(result).toMatchObject(expected); const actualContext = result.context; - expect(actualContext).toHaveProperty(TS_KEY); - const ts: ITimestampsHash = actualContext[TS_KEY]; + expect(actualContext).toHaveProperty(KEY_TS); + const ts: ITimestamps = actualContext[KEY_TS]; expect(typeof ts).toBe("object"); expect(ts).toHaveProperty(side); expect(ts[side]).toHaveProperty("log"); @@ -124,8 +123,8 @@ function testContextSourcing(): void { const host = hostname(); // Const objects are not immutable: catch details being overwritten. - const details = { a: "A" }; - const expectedDetails = { ...details }; + const details: IDetails = { a: "A" }; + const expectedDetails: IDetails = { ...details }; const clientContext: IContext = { processorObject: { foo: "bar" }, @@ -139,16 +138,16 @@ function testContextSourcing(): void { const t1: number = +new Date() - 3; const initialContext = { - [DETAILS_KEY]: expectedDetails, - // HOST_KEY: not on client contexts. - [TS_KEY]: { + [KEY_DETAILS]: expectedDetails, + // KEY_HOST: not on client contexts. + [KEY_TS]: { [side]: { log: t1 + 1, send: t1 + 2, - } as ITimestamps, + }, // No "server" yet. - } as ITimestampsHash, - [SOURCE_KEY]: side, + } as ITimestamps, + [KEY_SOURCE]: side, [side]: clientContext, }; @@ -157,10 +156,10 @@ function testContextSourcing(): void { const expected = { context: { - [DETAILS_KEY]: expectedDetails, - [HOST_KEY]: host, - [SOURCE_KEY]: side, - // TS_KEY: Cannot test content just with toMatchObject. + [KEY_DETAILS]: expectedDetails, + [KEY_HOST]: host, + [KEY_SOURCE]: side, + // KEY_TS: Cannot test content just with toMatchObject. [side]: expectedClientContext, // No "server" content without a server processor. }, @@ -178,9 +177,9 @@ function testContextSourcing(): void { // No side property without a processor. expect(actualContext).not.toHaveProperty("server"); - expect(actualContext).toHaveProperty(TS_KEY); - const ts: ITimestampsHash = actualContext[TS_KEY]; - expect(typeof actualContext[TS_KEY]).toBe("object"); + expect(actualContext).toHaveProperty(KEY_TS); + const ts: ITimestamps = actualContext[KEY_TS]; + expect(typeof actualContext[KEY_TS]).toBe("object"); expect(typeof ts).toBe("object"); expect(ts).toHaveProperty(side); expect(ts).toHaveProperty("server"); diff --git a/__tests__/unit/logContextTest.ts b/__tests__/unit/logContextTest.ts index 3bdbcca..cfd553b 100644 --- a/__tests__/unit/logContextTest.ts +++ b/__tests__/unit/logContextTest.ts @@ -1,4 +1,4 @@ -import {DETAILS_KEY, IContext, SOURCE_KEY, TS_KEY } from "../../src/IContext"; +import {KEY_DETAILS, IContext, KEY_SOURCE, KEY_TS } from "../../src/IContext"; import {Logger} from "../../src/Loggers/Logger"; import {ServerLogger} from "../../src/Loggers/ServerLogger"; import * as LogLevel from "../../src/LogLevel"; @@ -35,12 +35,12 @@ function testMessageContext() { * * - log { message_details: { a: 1} }. */ - test(`should add the message argument to ${DETAILS_KEY}`, () => { + test(`should add the message argument to ${KEY_DETAILS}`, () => { const testSender: TestSender = new TestSender(); const logger = new Logger(newLogStrategy(testSender)); logger.log(LogLevel.DEBUG, "some message", referenceContext()); - const actualDetails = testSender.result.context[DETAILS_KEY]; + const actualDetails = testSender.result.context[KEY_DETAILS]; const expected = "A"; // Message details is set expect(actualDetails).toHaveProperty("a", expected); @@ -68,27 +68,27 @@ function testMessageContext() { * - log { message_details: { a: "A", message_details: { foo: "bar" } } }, * unlike the message_details merging it did until 0.1.18 included. */ - test(`should not merge contents of existing ${DETAILS_KEY} context key`, () => { + test(`should not merge contents of existing ${KEY_DETAILS} context key`, () => { const sender = new TestSender(); const logger = new Logger(newLogStrategy(sender)); - const originalContext = Object.assign({ [DETAILS_KEY]: { foo: "bar" } }, referenceContext()); + const originalContext = { [KEY_DETAILS]: { foo: "bar" }, ...referenceContext() }; logger.log(LogLevel.DEBUG, "some message", originalContext); const actual = sender.result.context; expect(actual).not.toHaveProperty("a"); expect(actual).not.toHaveProperty("foo"); - expect(actual).toHaveProperty(DETAILS_KEY); + expect(actual).toHaveProperty(KEY_DETAILS); // Original top-level keys should still be in top [KEY_DETAILS]. - const actualDetails = actual[DETAILS_KEY]; + const actualDetails = actual[KEY_DETAILS]; expect(actualDetails).toHaveProperty("a", "A"); - expect(actualDetails).toHaveProperty(DETAILS_KEY); + expect(actualDetails).toHaveProperty(KEY_DETAILS); expect(actualDetails).not.toHaveProperty("foo"); // Key nested in original message_detail should remain in place. - const actualNested = actualDetails[DETAILS_KEY]; + const actualNested = actualDetails[KEY_DETAILS]; expect(actualNested).not.toHaveProperty("a", "A"); - expect(actualNested).not.toHaveProperty(DETAILS_KEY); + expect(actualNested).not.toHaveProperty(KEY_DETAILS); expect(actualNested).toHaveProperty("foo", "bar"); }); @@ -98,28 +98,28 @@ function testMessageContext() { * - log { message_details: { a: "A", message_details: { a: "A" } } }, * unlike the message_details merging it did until 0.1.18 included. */ - test(`should not merge existing ${DETAILS_KEY} context key itself`, () => { + test(`should not merge existing ${KEY_DETAILS} context key itself`, () => { const sender = new TestSender(); const logger = new Logger(newLogStrategy(sender)); - const originalContext = Object.assign({ [DETAILS_KEY]: { a: "A" } }, referenceContext()); + const originalContext = { [KEY_DETAILS]: { a: "A" }, ...referenceContext() }; logger.log(LogLevel.DEBUG, "some message", originalContext); - // Message_details should only contain a nested [DETAILS_KEY]. + // Message_details should only contain a nested [KEY_DETAILS]. const actual = sender.result.context; const keys = Object.keys(actual).sort(); expect(keys.length).toBe(3); - expect(keys).toEqual([DETAILS_KEY, SOURCE_KEY, TS_KEY]); - expect(actual).toHaveProperty(DETAILS_KEY); + expect(keys).toEqual([KEY_DETAILS, KEY_SOURCE, KEY_TS]); + expect(actual).toHaveProperty(KEY_DETAILS); // Original top-level keys should still be in top [KEY_DETAILS]. - const actualDetails = actual[DETAILS_KEY]; + const actualDetails = actual[KEY_DETAILS]; expect(Object.keys(actualDetails).length).toBe(2); expect(actualDetails).toHaveProperty("a", "A"); - expect(actualDetails).toHaveProperty(DETAILS_KEY); + expect(actualDetails).toHaveProperty(KEY_DETAILS); // Key nested in original message_detail should remain in place. - const actualNested = actualDetails[DETAILS_KEY]; + const actualNested = actualDetails[KEY_DETAILS]; expect(Object.keys(actualNested).length).toBe(1); expect(actualNested).toHaveProperty("a", "A"); }); @@ -129,15 +129,15 @@ function testMessageContext() { * * - log { message_details: { a: "A", message_details: { a: "B" } } }. */ - test(`should not merge keys within ${DETAILS_KEY}`, () => { + test(`should not merge keys within ${KEY_DETAILS}`, () => { const sender = new TestSender(); const logger = new Logger(newLogStrategy(sender)); - const originalContext = Object.assign({ [DETAILS_KEY]: { a: "B" } }, referenceContext()); + const originalContext = { [KEY_DETAILS]: { a: "B" }, ...referenceContext() }; logger.log(LogLevel.DEBUG, "some message", originalContext); // [KEY_DETAILS] should contain the newly added value for key "a", not the - // one present in the initial [DETAILS_KEY]. - const actualDetails: { a?: any } = sender.result.context[DETAILS_KEY]; + // one present in the initial [KEY_DETAILS]. + const actualDetails: { a?: any } = sender.result.context[KEY_DETAILS]; const expected = "A"; // Message details are set. expect(actualDetails).toHaveProperty("a", expected); @@ -256,7 +256,10 @@ function testObjectifyContext() { let expected: string | Foo = "object"; expect(actual).toBe(expected); - actual = initial.constructor.name; + interface IConstructor extends Function { + name: string; + } + actual = (initial.constructor as IConstructor).name; expected = "Foo"; expect(actual).toBe(expected); @@ -310,7 +313,7 @@ function testProcessors() { const Adder = class extends ProcessorBase implements IProcessor { public process(context) { - return Object.assign({ added: "value" }, context); + return { added: "value", ...context }; } }; @@ -342,7 +345,7 @@ function testProcessors() { const TimeWarp = class extends ProcessorBase { // Let's do the time warp again. public process(context: IContext): IContext { - context[TS_KEY] = { + context[KEY_TS] = { test: { log: +new Date("1978-11-19 05:00:00") }, }; context.hostname = "remote"; @@ -410,8 +413,8 @@ function testProcessors() { expect(this.sender.logs.length).toBe(1); const [, , context] = this.sender.logs.pop(); expect(context).toHaveProperty("hostname", "local"); - expect(context).toHaveProperty(`${TS_KEY}.${this.logger.side}.log`); - const lag = ts - context[TS_KEY][this.logger.side].log; + expect(context).toHaveProperty(`${KEY_TS}.${this.logger.side}.log`); + const lag = ts - context[KEY_TS][this.logger.side].log; expect(lag).toBeGreaterThanOrEqual(0); // No sane machine should take more than 100 msec to return from log() with // such a fast sending configuration. @@ -426,8 +429,8 @@ function testProcessors() { expect(this.sender.logs.length).toBe(1); const [, , context] = this.sender.logs.pop(); expect(context).toHaveProperty("hostname", "remote"); - expect(context).toHaveProperty(`${TS_KEY}.${this.logger.side}.log`); - const lag = ts - context[TS_KEY][this.logger.side].log; + expect(context).toHaveProperty(`${KEY_TS}.${this.logger.side}.log`); + const lag = ts - context[KEY_TS][this.logger.side].log; expect(lag).toBeGreaterThanOrEqual(0); // No sane machine should take more than 100 msec to return from log() with // such a fast sending configuration. The TimeWarp processor attempts to diff --git a/__tests__/unit/mongodbSenderTest.ts b/__tests__/unit/mongodbSenderTest.ts index 8210878..9809635 100644 --- a/__tests__/unit/mongodbSenderTest.ts +++ b/__tests__/unit/mongodbSenderTest.ts @@ -1,7 +1,7 @@ import sinon = require("sinon"); -import {TS_KEY} from "../../src/IContext"; +import {IContext, IDetails, KEY_TS} from "../../src/IContext"; import * as LogLevel from "../../src/LogLevel"; -import MongoDbSender from "../../src/Senders/MongodbSender"; +import { MongodbSender } from "../../src/Senders/MongodbSender"; // This is a builtin Meteor interface: cannot rename it. // tslint:disable-next-line @@ -24,34 +24,34 @@ function testMongoDbSender() { test("should accept a collection name", () => { const spy = sinon.spy(mongo, "Collection"); - const sender = new MongoDbSender(mongo, "some_collection"); - expect(sender).toBeInstanceOf(MongoDbSender); + const sender = new MongodbSender(mongo, "some_collection"); + expect(sender).toBeInstanceOf(MongodbSender); expect(spy.calledOnce).toBe(true); }); test("should accept an existing collection", () => { const collection = new mongo.Collection("fake"); - const sender = new MongoDbSender(mongo, collection); - expect(sender).toBeInstanceOf(MongoDbSender); + const sender = new MongodbSender(mongo, collection); + expect(sender).toBeInstanceOf(MongodbSender); expect(sender.store).toBe(collection); }); test("should reject invalid collection values", () => { const collection = 42; // Force type to accept invalid data. - expect(() => new MongoDbSender(mongo, collection as any)).toThrowError(Error); + expect(() => new MongodbSender(mongo, collection as any)).toThrowError(Error); }); test("should add a \"send\" timestamp to empty context", () => { const collection = new mongo.Collection("fake"); - const sender = new MongoDbSender(mongo, collection); + const sender = new MongodbSender(mongo, collection); const insertSpy = sinon.spy(sender.store, "insert"); const before = +new Date(); const level: LogLevel.Levels = LogLevel.WARNING; const message = "message"; - const details = {}; + const context: IContext = {}; - sender.send(level, message, details); + sender.send(level, message, context); const after = +new Date(); // Collection.insert was called once. @@ -63,7 +63,7 @@ function testMongoDbSender() { // Message is passed. expect(callArgs.message).toBe(message); - const timestamp = callArgs.context[TS_KEY].server.send; + const timestamp = callArgs.context[KEY_TS].server.send; // A numeric store timestamp is passed. expect(typeof timestamp).toBe("number"); // Timestamp is later than 'before'. @@ -74,18 +74,20 @@ function testMongoDbSender() { test("should add a \"send\" timestamp to non-empty context", () => { const collection = new mongo.Collection("fake"); - const sender = new MongoDbSender(mongo, collection); + const sender = new MongodbSender(mongo, collection); const insertSpy = sinon.spy(sender.store, "insert"); const before = +new Date(); const level: LogLevel.Levels = LogLevel.Levels.WARNING; const message = "message"; - const details = { - [TS_KEY]: { - whatever: 1480849124018, + const context: IContext = { + [KEY_TS]: { + whatever: { + rocks: 1480849124018, + }, }, }; - sender.send(level, message, details); + sender.send(level, message, context); const after = +new Date(); // Collection.insert was called once. expect(insertSpy.calledOnce).toBe(true); @@ -95,7 +97,7 @@ function testMongoDbSender() { // Message is passed. expect(callArgs.message).toBe(message); - const timestamp = callArgs.context[TS_KEY].server.send; + const timestamp = callArgs.context[KEY_TS].server.send; // A numeric store timestamp is passed. expect(typeof timestamp).toBe("number"); // Timestamp is later than 'before'. diff --git a/__tests__/unit/serializationTest.ts b/__tests__/unit/serializationTest.ts index ecf260a..01e9899 100644 --- a/__tests__/unit/serializationTest.ts +++ b/__tests__/unit/serializationTest.ts @@ -1,6 +1,6 @@ const sinon = require("sinon"); -import SyslogSender from "../../src/Senders/SyslogSender"; +import { SyslogSender } from "../../src/Senders/SyslogSender"; function testSerializeDeepObject() { const LOCAL0 = 16; diff --git a/__tests__/unit/serverLoggerTest.ts b/__tests__/unit/serverLoggerTest.ts index aab9672..6a2b61e 100644 --- a/__tests__/unit/serverLoggerTest.ts +++ b/__tests__/unit/serverLoggerTest.ts @@ -1,13 +1,33 @@ +import * as os from "os"; import sinon = require("sinon"); -import {DETAILS_KEY, IContext, SOURCE_KEY, TS_KEY} from "../../src/IContext"; +import { + KEY_DETAILS, + IContext, + IDetails, + KEY_SOURCE, + KEY_TS, KEY_HOST, ITimestamps, +} from "../../src/IContext"; +import { + ClientSide, +} from "../../src/Loggers/ClientLogger"; import {ILogger} from "../../src/Loggers/ILogger"; -import { IServerLoggerConstructorParameters, ServerLogger } from "../../src/Loggers/ServerLogger"; +import { + IServerLoggerConstructorParameters, + ServerLogger, + ServerSide, +} from "../../src/Loggers/ServerLogger"; import * as LogLevel from "../../src/LogLevel"; import NullFn from "../../src/NullFn"; import {IProcessor} from "../../src/Processors/IProcessor"; import ProcessorBase from "../../src/Processors/ProcessorBase"; -import {IResult, newEmptyStrategy, newLogStrategy, TestSender} from "./types"; +import { + IConstructor, + IResult, + newEmptyStrategy, + newLogStrategy, + TestSender, +} from "./types"; const LOG_SOURCE = "test"; const MAGIC = "xyzzy"; @@ -68,25 +88,25 @@ const testConnect = () => { test("Should only register with connect when WebApp is passed", () => { const loggerHappy = new ServerLogger(newEmptyStrategy(), mockWebApp as any, {}); - expect(loggerHappy.constructor.name).toBe("ServerLogger"); + expect((loggerHappy.constructor as IConstructor).name).toBe("ServerLogger"); expect(connectSpy.calledOnce).toBe(true); connectSpy.resetHistory(); const loggerSad = new ServerLogger(newEmptyStrategy(), null, {}); - expect(loggerSad.constructor.name).toBe("ServerLogger"); + expect((loggerSad.constructor as IConstructor).name).toBe("ServerLogger"); expect(connectSpy.calledOnce).toBe(true); }); test("Should register with connect with default path", () => { const logger = new ServerLogger(newEmptyStrategy(), mockWebApp as any, {}); - expect(logger.constructor.name).toBe("ServerLogger"); + expect((logger.constructor as IConstructor).name).toBe("ServerLogger"); expect(connectSpy.alwaysCalledWith(mockWebApp, "/logger")).toBe(true); }); test("Should register with connect with chosen path", () => { const servePath = "/eightfold"; const logger = new ServerLogger(newEmptyStrategy(), mockWebApp as any, { servePath }); - expect(logger.constructor.name).toBe("ServerLogger"); + expect((logger.constructor as IConstructor).name).toBe("ServerLogger"); expect(connectSpy.calledOnce).toBe(true); expect(connectSpy.alwaysCalledWith(mockWebApp, servePath)).toBe(true); }); @@ -96,11 +116,11 @@ const testBuildContext = () => { test("Should apply logger source over context", () => { const logger: ServerLogger = new ServerLogger(newEmptyStrategy()); logger.side = LOG_SOURCE; - const details: {} = { - [SOURCE_KEY]: "other", + const details: IDetails = { + [KEY_SOURCE]: "other", }; const actual = logger.getInitialContext(details); - expect(actual).toHaveProperty(SOURCE_KEY, LOG_SOURCE); + expect(actual).toHaveProperty(KEY_SOURCE, LOG_SOURCE); }); test("Should import details as details key", () => { @@ -109,7 +129,7 @@ const testBuildContext = () => { const actual = logger.getInitialContext(argumentDetails); const expected = { // Argument detail overwrites context detail. - [DETAILS_KEY]: argumentDetails, + [KEY_DETAILS]: argumentDetails, }; expect(actual).toMatchObject(expected); }); @@ -157,7 +177,7 @@ const testLogExtended = () => { const t0 = + new Date(); const clientTsKey = "whatever"; const sourceContext = { - [TS_KEY]: { + [KEY_TS]: { [LOG_SOURCE]: { [clientTsKey]: t0, }, @@ -165,18 +185,20 @@ const testLogExtended = () => { }; logger.logExtended(LogLevel.INFO, "message", sourceContext, LOG_SOURCE); const result: IResult = sender.result; - expect(result).not.toHaveProperty(`context.${LOG_SOURCE}.${TS_KEY}`); - expect(result).toHaveProperty(`context.${TS_KEY}`); - expect(result).toHaveProperty(`context.${TS_KEY}.${LOG_SOURCE}`); - expect(result).toHaveProperty(`context.${TS_KEY}.${LOG_SOURCE}.${clientTsKey}`); - const actual = result.context[TS_KEY][LOG_SOURCE][clientTsKey]; + expect(result).not.toHaveProperty(`context.${LOG_SOURCE}.${KEY_TS}`); + expect(result).toHaveProperty(`context.${KEY_TS}`); + expect(result).toHaveProperty(`context.${KEY_TS}.${LOG_SOURCE}`); + expect(result).toHaveProperty(`context.${KEY_TS}.${LOG_SOURCE}.${clientTsKey}`); + const actual = result.context[KEY_TS][LOG_SOURCE][clientTsKey]; expect(actual).toBe(t0); }); - // TODO: processors are not yet implemented in this branch. - test.skip("Should apply processors", () => { + test("Should apply processors", () => { const sender = new TestSender(); - const logger = new ServerLogger(newLogStrategy(sender), null, { foo: "bar" } as IServerLoggerConstructorParameters); + // Cast is required because this is an illegal key, which would otherwise + // be unusable in TS: this test is only for the generated JS. + const parameters = { foo: "bar" } as IServerLoggerConstructorParameters; + const logger = new ServerLogger(newLogStrategy(sender), null, parameters); const P1 = class extends ProcessorBase implements IProcessor { /** @inheritDoc */ @@ -192,32 +214,47 @@ const testLogExtended = () => { }; logger.processors.push(new P1()); logger.processors.push(new P2()); - const initialContext = { - // Should remain. - c: "C", - // Should be overwritten twice. - extra: "initial", + const initialContext: IContext = { + [KEY_SOURCE]: LOG_SOURCE, + [LOG_SOURCE]: { + // Should remain. + c: "C", + }, + [ServerSide]: { + // Should be overwritten twice. + extra: "initial", + // Should remain. + s: "S", + }, }; + + const hostname = os.hostname(); + logger.logExtended(LogLevel.INFO, "message", initialContext, LOG_SOURCE); - // Expected: { - // message_details: (..not tested here..), - // source: "test", - // test: { c: "C", extra: "initial" }, - // server: { p1: "p1", p2: "p2", extra: "p2" } - // timestamp: (..not tested here..) - // } + const expectedContext: IContext = { + // No [KEY_DETAILS]: any. + [KEY_HOST]: hostname, + [KEY_SOURCE]: LOG_SOURCE, + // [KEY_TS]: more complex to test, and irrelevant here, so not expected. + [LOG_SOURCE]: { c: "C" }, + [ServerSide]: { + // Extra is "initial" originally, "p1" after p1, and "p2" after p2. + extra: "p2", + p1: "p1", + p2: "p2", + s: "S", + }, + }; const result: IResult = sender.result; expect(result).toHaveProperty("context"); - const actual = result.context; - expect(actual).not.toHaveProperty("c"); - expect(actual).not.toHaveProperty("p1"); - expect(actual).not.toHaveProperty("p2"); - expect(actual).not.toHaveProperty("extra"); - expect(actual).toHaveProperty(LOG_SOURCE, initialContext); - expect(actual).toHaveProperty(ServerLogger.side); - expect(actual[ServerLogger.side]).toHaveProperty("p1", "p1"); - expect(actual[ServerLogger.side]).toHaveProperty("p2", "p2"); - expect(actual[ServerLogger.side]).toHaveProperty("extra", "p2"); + const actualContext: IContext = result.context; + expect(actualContext).not.toHaveProperty(KEY_DETAILS); + expect(actualContext).not.toHaveProperty(ClientSide); + expect(actualContext).toHaveProperty(KEY_TS); + const actualTs: ITimestamps = actualContext[KEY_TS]; + expect(actualTs).toHaveProperty(`${ServerSide}.log`); + + expect(actualContext).toMatchObject(expectedContext); }); }; diff --git a/__tests__/unit/strategyTest.ts b/__tests__/unit/strategyTest.ts index f16f6e6..76d7ddb 100644 --- a/__tests__/unit/strategyTest.ts +++ b/__tests__/unit/strategyTest.ts @@ -1,5 +1,6 @@ -import LeveledStrategy from "../../src/Strategies/LeveledStrategy"; -import NullSender from "../../src/Senders/NullSender"; +import { NullSender } from "../../src/Senders/NullSender"; +import { LeveledStrategy } from "../../src/Strategies/LeveledStrategy"; +import {ISender} from "../../src/Senders/ISender"; function testStrategyConstruction() { "use strict"; @@ -19,9 +20,9 @@ function testStrategyConstruction() { test("Should reject non-senders passed as senders at any position", () => { const nullSender = new NullSender(); - expect(() => new LeveledStrategy({}, nullSender, nullSender)).toThrow(); - expect(() => new LeveledStrategy(nullSender, {}, nullSender)).toThrow(); - expect(() => new LeveledStrategy(nullSender, nullSender, {}).toThrow()); + expect(() => new LeveledStrategy({} as ISender, nullSender, nullSender)).toThrow(); + expect(() => new LeveledStrategy(nullSender, {} as ISender, nullSender)).toThrow(); + expect(() => new LeveledStrategy(nullSender, nullSender, {} as ISender)).toThrow(); }); } diff --git a/__tests__/unit/test.ts b/__tests__/unit/test.ts index 71ff62d..c6e4500 100644 --- a/__tests__/unit/test.ts +++ b/__tests__/unit/test.ts @@ -41,7 +41,7 @@ describe("Unit", () => { }); describe("Senders", () => { describe("ConsoleSender", testConsoleSender); - describe("MongoDbSender", testMongoDbSender); + describe("MongodbSender", testMongoDbSender); }); describe("MeteorUserProcessor", testMeteorUserProcessor); describe("BrowserProcessor", testBrowserProcessor); diff --git a/__tests__/unit/types.ts b/__tests__/unit/types.ts index 78a29f7..72a3932 100644 --- a/__tests__/unit/types.ts +++ b/__tests__/unit/types.ts @@ -10,13 +10,29 @@ const newEmptyStrategy: StrategyFactory = () => ({ selectSenders: () => [], }); +/** + * This extension is only for tests checking .constructor.name. + * + * In normal code, the constructor name may be mangled or unavailable after + * minification, so no userland code should use it. But since test code is not + * minimized, it is still useful in that case. + * + * @internal + */ +interface IConstructor extends Function { + name: string; +} + interface IResult { level?: LogLevel.Levels; message?: string; context?: IContext; } -class TestSender { +/** + * A Sender class storing results internally, for review by tests. + */ +class TestSender implements ISender { public result: IResult = {}; public send(level, message, context): void { @@ -30,6 +46,7 @@ const newLogStrategy: StrategyFactory = (sender: TestSender) => ({ }); export { + IConstructor, IResult, StrategyFactory, newEmptyStrategy, diff --git a/jest.config.js b/jest.config.js index 3c8a0fa..3d6c706 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,9 +1,4 @@ module.exports = { - "globals": { - "ts-jest": { - "tsConfigFile": "tsconfig.json" - } - }, moduleFileExtensions: [ "ts", "tsx", diff --git a/lib/IContext.d.ts b/lib/IContext.d.ts index 98e0a54..8cfe77b 100644 --- a/lib/IContext.d.ts +++ b/lib/IContext.d.ts @@ -1,21 +1,62 @@ -declare const DETAILS_KEY = "message_details"; -declare const HOST_KEY = "hostname"; -declare const SOURCE_KEY = "source"; -declare const TS_KEY = "timestamp"; +/** + * @fileOverview + * Basic data structures used during logging. + */ +declare const KEY_DETAILS = "message_details"; +declare const KEY_HOST = "hostname"; +declare const KEY_SOURCE = "source"; +declare const KEY_TS = "timestamp"; +/** + * The data accompanying a log event. + * + * - KEY_DETAILS: the details passed to the log() call by the application. + * - KEY_HOST: the host on which a hostname could first be found. This is + * usually the hostname of the Meteor server handling the request. + * - KEY_SOURCE: the source of the log event. In normal usage, it will be one of + * "client", "cordova", or "server", but can be any other string and tests, + * especially are expected to make use of other values. + * - KEY_TS: the timestamps chain taken while handling the log event. + * - "side" keys represent the additional context data added by processors on + * each side in a log chain. + * + * In practice, this means that log events emitted on a browser or mobile app + * will have two such keys: one for the source of the event ("client" or + * "cordova"), and one ("server") for the context added by the server handling + * the logging. Conversely, log events emitted on the server, e.g. during + * startup or a Meteor method call, will only have context added under the + * "server" key. + */ +interface IContext { + [KEY_DETAILS]?: IDetails; + [KEY_HOST]?: string; + [KEY_SOURCE]?: string; + [KEY_TS]?: ITimestamps; + [side: string]: {} | undefined; +} +/** + * The type of data passed along the level and message in ILogger.log() calls. + * + * It is expected to mostly contain values for placeholders in the string + * representation of the message, in PSR-3 format (braces). + * + * @see IContext + */ interface IDetails { - [HOST_KEY]?: string; + [key: string]: any; } +/** + * The time of the data under the KEY_TS in IContext. + * + * Its structure allows the conservation or relative time sequence on different + * hosts in a client->server or mobile->server chain by segregating timestamps + * by side performing the timestamping, avoiding issues with time drift in + * loosely coordinated hosts. + * + * @see IContext + */ interface ITimestamps { - [op: string]: number; -} -interface ITimestampsHash { - [side: string]: ITimestamps; -} -interface IContext { - [DETAILS_KEY]?: {}; - [HOST_KEY]?: string; - [SOURCE_KEY]?: string; - [TS_KEY]?: ITimestampsHash; - [key: string]: {} | undefined; + [side: string]: { + [op: string]: number; + }; } -export { DETAILS_KEY, HOST_KEY, SOURCE_KEY, TS_KEY, IDetails, IContext, ITimestamps, ITimestampsHash, }; +export { IContext, IDetails, ITimestamps, KEY_DETAILS, KEY_HOST, KEY_SOURCE, KEY_TS, }; diff --git a/lib/IContext.js b/lib/IContext.js index 72df881..57f33a9 100644 --- a/lib/IContext.js +++ b/lib/IContext.js @@ -1,11 +1,15 @@ "use strict"; +/** + * @fileOverview + * Basic data structures used during logging. + */ Object.defineProperty(exports, "__esModule", { value: true }); -var DETAILS_KEY = "message_details"; -exports.DETAILS_KEY = DETAILS_KEY; -var HOST_KEY = "hostname"; -exports.HOST_KEY = HOST_KEY; -var SOURCE_KEY = "source"; -exports.SOURCE_KEY = SOURCE_KEY; -var TS_KEY = "timestamp"; -exports.TS_KEY = TS_KEY; +var KEY_DETAILS = "message_details"; +exports.KEY_DETAILS = KEY_DETAILS; +var KEY_HOST = "hostname"; +exports.KEY_HOST = KEY_HOST; +var KEY_SOURCE = "source"; +exports.KEY_SOURCE = KEY_SOURCE; +var KEY_TS = "timestamp"; +exports.KEY_TS = KEY_TS; //# sourceMappingURL=IContext.js.map \ No newline at end of file diff --git a/lib/IContext.js.map b/lib/IContext.js.map index 72b1dac..a18b5e8 100644 --- a/lib/IContext.js.map +++ b/lib/IContext.js.map @@ -1 +1 @@ -{"version":3,"file":"IContext.js","sourceRoot":"","sources":["../src/IContext.ts"],"names":[],"mappings":";;AAAA,IAAM,WAAW,GAAG,iBAAiB,CAAC;AA2BpC,kCAAW;AA1Bb,IAAM,QAAQ,GAAG,UAAU,CAAC;AA2B1B,4BAAQ;AA1BV,IAAM,UAAU,GAAG,QAAQ,CAAC;AA2B1B,gCAAU;AA1BZ,IAAM,MAAM,GAAG,WAAW,CAAC;AA2BzB,wBAAM"} \ No newline at end of file +{"version":3,"file":"IContext.js","sourceRoot":"","sources":["../src/IContext.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,IAAM,WAAW,GAAG,iBAAiB,CAAC;AAkEpC,kCAAW;AAjEb,IAAM,QAAQ,GAAG,UAAU,CAAC;AAkE1B,4BAAQ;AAjEV,IAAM,UAAU,GAAG,QAAQ,CAAC;AAkE1B,gCAAU;AAjEZ,IAAM,MAAM,GAAG,WAAW,CAAC;AAkEzB,wBAAM"} \ No newline at end of file diff --git a/lib/LogLevel.d.ts b/lib/LogLevel.d.ts index 2042680..6255539 100644 --- a/lib/LogLevel.d.ts +++ b/lib/LogLevel.d.ts @@ -1,5 +1,6 @@ /** - * @fileOverview Package exported constants. + * @fileOverview + * Package exported constants. */ declare const Names: string[]; declare const EMERGENCY = 0; diff --git a/lib/LogLevel.js b/lib/LogLevel.js index 1e5a595..3a3b0ca 100644 --- a/lib/LogLevel.js +++ b/lib/LogLevel.js @@ -1,6 +1,7 @@ "use strict"; /** - * @fileOverview Package exported constants. + * @fileOverview + * Package exported constants. */ Object.defineProperty(exports, "__esModule", { value: true }); var Names = [ diff --git a/lib/LogLevel.js.map b/lib/LogLevel.js.map index 02d2146..f761ac3 100644 --- a/lib/LogLevel.js.map +++ b/lib/LogLevel.js.map @@ -1 +1 @@ -{"version":3,"file":"LogLevel.js","sourceRoot":"","sources":["../src/LogLevel.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,IAAM,KAAK,GAAG;IACZ,WAAW;IACX,OAAO;IACP,UAAU;IACV,OAAO;IACP,SAAS;IACT,QAAQ;IACR,eAAe;IACf,OAAO;CACR,CAAC;AAyBA,sBAAK;AAvBP,IAAM,SAAS,GAAG,CAAC,CAAC;AA0BlB,8BAAS;AAzBX,IAAM,KAAK,GAAG,CAAC,CAAC;AA0Bd,sBAAK;AAzBP,IAAM,QAAQ,GAAG,CAAC,CAAC;AA0BjB,4BAAQ;AAzBV,IAAM,KAAK,GAAG,CAAC,CAAC;AA0Bd,sBAAK;AAzBP,IAAM,OAAO,GAAG,CAAC,CAAC;AA0BhB,0BAAO;AAzBT,IAAM,MAAM,GAAG,CAAC,CAAC;AA0Bf,wBAAM;AAzBR,IAAM,aAAa,GAAG,CAAC,CAAC;AA2BtB,sCAAa;AA1Bf,IAAM,IAAI,GAAG,CAAC,CAAC;AAyBb,oBAAI;AAxBN,IAAM,KAAK,GAAG,CAAC,CAAC;AA0Bd,sBAAK;AAxBP,IAAK,MAUJ;AAVD,WAAK,MAAM;IACT,6CAAS,CAAA;IACT,qCAAK,CAAA;IACL,2CAAQ,CAAA;IACR,qCAAK,CAAA;IACL,yCAAO,CAAA;IACP,uCAAM,CAAA;IACN,qDAAiB,CAAA;IACjB,mCAAQ,CAAA;IACR,qCAAK,CAAA;AACP,CAAC,EAVI,MAAM,KAAN,MAAM,QAUV;AAIC,wBAAM"} \ No newline at end of file +{"version":3,"file":"LogLevel.js","sourceRoot":"","sources":["../src/LogLevel.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,IAAM,KAAK,GAAG;IACZ,WAAW;IACX,OAAO;IACP,UAAU;IACV,OAAO;IACP,SAAS;IACT,QAAQ;IACR,eAAe;IACf,OAAO;CACR,CAAC;AAyBA,sBAAK;AAvBP,IAAM,SAAS,GAAG,CAAC,CAAC;AA0BlB,8BAAS;AAzBX,IAAM,KAAK,GAAG,CAAC,CAAC;AA0Bd,sBAAK;AAzBP,IAAM,QAAQ,GAAG,CAAC,CAAC;AA0BjB,4BAAQ;AAzBV,IAAM,KAAK,GAAG,CAAC,CAAC;AA0Bd,sBAAK;AAzBP,IAAM,OAAO,GAAG,CAAC,CAAC;AA0BhB,0BAAO;AAzBT,IAAM,MAAM,GAAG,CAAC,CAAC;AA0Bf,wBAAM;AAzBR,IAAM,aAAa,GAAG,CAAC,CAAC;AA2BtB,sCAAa;AA1Bf,IAAM,IAAI,GAAG,CAAC,CAAC;AAyBb,oBAAI;AAxBN,IAAM,KAAK,GAAG,CAAC,CAAC;AA0Bd,sBAAK;AAxBP,IAAK,MAUJ;AAVD,WAAK,MAAM;IACT,6CAAS,CAAA;IACT,qCAAK,CAAA;IACL,2CAAQ,CAAA;IACR,qCAAK,CAAA;IACL,yCAAO,CAAA;IACP,uCAAM,CAAA;IACN,qDAAiB,CAAA;IACjB,mCAAQ,CAAA;IACR,qCAAK,CAAA;AACP,CAAC,EAVI,MAAM,KAAN,MAAM,QAUV;AAIC,wBAAM"} \ No newline at end of file diff --git a/lib/Loggers/ClientLogger.d.ts b/lib/Loggers/ClientLogger.d.ts index 49185ee..d706878 100644 --- a/lib/Loggers/ClientLogger.d.ts +++ b/lib/Loggers/ClientLogger.d.ts @@ -3,22 +3,18 @@ */ import { IStrategy } from "../Strategies/IStrategy"; import { Logger } from "./Logger"; +declare const SIDE = "client"; /** * ClientLogger is the client-side implementation of Logger. * * In its current state, it brings nothing over Logger, simply providing an * extension-specialization point. - * - * @extends Logger - * - * @property {string} side */ declare class ClientLogger extends Logger { - static readonly side: string; constructor(strategy: IStrategy); /** * @inheritDoc */ protected getHostname(): string | undefined; } -export { ClientLogger, }; +export { ClientLogger, SIDE as ClientSide, }; diff --git a/lib/Loggers/ClientLogger.js b/lib/Loggers/ClientLogger.js index 9c8c851..a6d40e9 100644 --- a/lib/Loggers/ClientLogger.js +++ b/lib/Loggers/ClientLogger.js @@ -18,15 +18,12 @@ var __extends = (this && this.__extends) || (function () { Object.defineProperty(exports, "__esModule", { value: true }); var Logger_1 = require("./Logger"); var SIDE = "client"; +exports.ClientSide = SIDE; /** * ClientLogger is the client-side implementation of Logger. * * In its current state, it brings nothing over Logger, simply providing an * extension-specialization point. - * - * @extends Logger - * - * @property {string} side */ var ClientLogger = /** @class */ (function (_super) { __extends(ClientLogger, _super); @@ -41,7 +38,6 @@ var ClientLogger = /** @class */ (function (_super) { ClientLogger.prototype.getHostname = function () { return undefined; }; - ClientLogger.side = SIDE; return ClientLogger; }(Logger_1.Logger)); exports.ClientLogger = ClientLogger; diff --git a/lib/Loggers/ClientLogger.js.map b/lib/Loggers/ClientLogger.js.map index ebcb4fb..7f94033 100644 --- a/lib/Loggers/ClientLogger.js.map +++ b/lib/Loggers/ClientLogger.js.map @@ -1 +1 @@ -{"version":3,"file":"ClientLogger.js","sourceRoot":"","sources":["../../src/Loggers/ClientLogger.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;AAGH,mCAAkC;AAElC,IAAM,IAAI,GAAG,QAAQ,CAAC;AAEtB;;;;;;;;;GASG;AACH;IAA2B,gCAAM;IAG/B,sBAAY,QAAmB;QAA/B,YACE,kBAAM,QAAQ,CAAC,SAEhB;QADC,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;;IACnB,CAAC;IAED;;OAEG;IACO,kCAAW,GAArB;QACE,OAAO,SAAS,CAAC;IACnB,CAAC;IAZsB,iBAAI,GAAG,IAAI,CAAC;IAarC,mBAAC;CAAA,AAdD,CAA2B,eAAM,GAchC;AAGC,oCAAY"} \ No newline at end of file +{"version":3,"file":"ClientLogger.js","sourceRoot":"","sources":["../../src/Loggers/ClientLogger.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;AAGH,mCAAkC;AAElC,IAAM,IAAI,GAAG,QAAQ,CAAC;AAyBZ,0BAAU;AAvBpB;;;;;GAKG;AACH;IAA2B,gCAAM;IAE/B,sBAAY,QAAmB;QAA/B,YACE,kBAAM,QAAQ,CAAC,SAEhB;QADC,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;;IACnB,CAAC;IAED;;OAEG;IACO,kCAAW,GAArB;QACE,OAAO,SAAS,CAAC;IACnB,CAAC;IACH,mBAAC;AAAD,CAAC,AAbD,CAA2B,eAAM,GAahC;AAGC,oCAAY"} \ No newline at end of file diff --git a/lib/Loggers/ILogger.d.ts b/lib/Loggers/ILogger.d.ts index 3093907..7e08b42 100644 --- a/lib/Loggers/ILogger.d.ts +++ b/lib/Loggers/ILogger.d.ts @@ -1,4 +1,4 @@ -import { IContext } from "../IContext"; +import { IContext, IDetails } from "../IContext"; import * as LogLevel from "../LogLevel"; interface ILogger { /** @@ -22,7 +22,7 @@ interface ILogger { * @see https://tools.ietf.org/html/rfc5424 * @see http://www.php-fig.org/psr/psr-3/ */ - log(level: LogLevel.Levels, message: string, context: IContext): void; + log(level: LogLevel.Levels, message: string, context: IDetails): void; /** * Implementation compatibility to replace Meteor.debug. * diff --git a/lib/Loggers/Logger.d.ts b/lib/Loggers/Logger.d.ts index d23abb4..8a5a590 100644 --- a/lib/Loggers/Logger.d.ts +++ b/lib/Loggers/Logger.d.ts @@ -1,7 +1,7 @@ /** * @fileOverview Base Logger class. */ -import { IContext, ITimestampsHash } from "../IContext"; +import { IContext, ITimestamps } from "../IContext"; import * as LogLevel from "../LogLevel"; import { IProcessor } from "../Processors/IProcessor"; import { IStrategy } from "../Strategies/IStrategy"; @@ -26,17 +26,19 @@ declare class Logger implements ILogger { /** * Add a timestamp to a context object on the active side. * - * Ensure a TS_KEY will be present, and existing timestamps are not being - * overwritten, except possibly for any value already present at [TS_KEY][op]. + * Ensure a KEY_TS will be present, and existing timestamps are not being + * overwritten, except possibly for any value already present at [KEY_TS][op]. * * @param context * Mutated. The context to stamp. * @param op * The operation for which to add a timestamp. + * @param side + * The side on which the operation is to be logged. * * @protected */ - static stamp(context: IContext, op: string, side: keyof ITimestampsHash): void; + static stamp(context: IContext, op: string, side: keyof ITimestamps): void; processors: IProcessor[]; side: string; tk: any; diff --git a/lib/Loggers/Logger.js b/lib/Loggers/Logger.js index 1ab859f..f1d5ac5 100644 --- a/lib/Loggers/Logger.js +++ b/lib/Loggers/Logger.js @@ -60,24 +60,26 @@ var Logger = /** @class */ (function () { /** * Add a timestamp to a context object on the active side. * - * Ensure a TS_KEY will be present, and existing timestamps are not being - * overwritten, except possibly for any value already present at [TS_KEY][op]. + * Ensure a KEY_TS will be present, and existing timestamps are not being + * overwritten, except possibly for any value already present at [KEY_TS][op]. * * @param context * Mutated. The context to stamp. * @param op * The operation for which to add a timestamp. + * @param side + * The side on which the operation is to be logged. * * @protected */ Logger.stamp = function (context, op, side) { var now = +new Date(); - // Ensure context actually contains a TS_KEY. - if (typeof context[IContext_1.TS_KEY] === "undefined") { - context[IContext_1.TS_KEY] = {}; + // Ensure context actually contains a KEY_TS. + if (typeof context[IContext_1.KEY_TS] === "undefined") { + context[IContext_1.KEY_TS] = {}; } - // We know context[TS_KEY] is defined because we just ensured it was. - var contextTs = context[IContext_1.TS_KEY]; + // We know context[KEY_TS] is defined because we just ensured it was. + var contextTs = context[IContext_1.KEY_TS]; var sideTs = contextTs[side] || {}; sideTs[op] = now; contextTs[side] = sideTs; @@ -136,12 +138,12 @@ var Logger = /** @class */ (function () { if (details === void 0) { details = {}; } var _a; var cx = (_a = {}, - _a[IContext_1.DETAILS_KEY] = details, - _a[IContext_1.SOURCE_KEY] = this.side, + _a[IContext_1.KEY_DETAILS] = details, + _a[IContext_1.KEY_SOURCE] = this.side, _a); var hostName = this._getHostname(); if (typeof hostName === "string") { - cx[IContext_1.HOST_KEY] = hostName; + cx[IContext_1.KEY_HOST] = hostName; } Logger.stamp(cx, "log", this.side); return cx; diff --git a/lib/Loggers/Logger.js.map b/lib/Loggers/Logger.js.map index 0f8d035..c760207 100644 --- a/lib/Loggers/Logger.js.map +++ b/lib/Loggers/Logger.js.map @@ -1 +1 @@ -{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Loggers/Logger.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;AAEH,sDAAgC;AAEhC,wCAKqB;AACrB,yFAAmE;AACnE,oDAAwC;AAKxC,mFAAmF;AAEnF,IAAM,IAAI,GAAG,SAAS,CAAC;AAEvB;;GAEG;AACH;IAwDE;;;;;;OAMG;IACH,gBAAmB,QAAmB;QAAnB,aAAQ,GAAR,QAAQ,CAAW;QAZ/B,eAAU,GAAiB,EAAE,CAAC;QAC9B,SAAI,GAAW,IAAI,CAAC;QAYzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,EAAE,GAAG,kBAAQ,CAAC;QAEnB,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAhED;;;;;;;;OAQG;IACW,gBAAS,GAAvB,UAAwB,KAAa;QACnC,IAAI,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,YAAY,GAAG,QAAQ,CAAC,SAAS,IAAI,KAAK,CAAC,YAAY,CAAC,EAAE;YAC5D,YAAY,GAAG,QAAQ,CAAC,SAAS,CAAC;SACnC;aAAM,IAAI,YAAY,GAAG,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AiBG;IACI,qBAAI,GAAX,UAAY,QAAmB,EAAE,KAAsB,EAAE,OAAe,EAAE,WAAe;QACvF,IAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;QACpE,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;YACrB,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;OAaG;IACI,8BAAa,GAApB,UAAqB,cAA+B;QAClD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAwB,CAAC;eAC1C,CAAC,cAAc,GAAG,QAAQ,CAAC,SAAS;eACpC,CAAC,cAAc,GAAG,QAAQ,CAAC,KAAK,EAAE;YACrC,MAAM,IAAI,kCAAwB,CAAC,uDAAuD,CAAC,CAAC;SAC7F;IACH,CAAC;IAED,kBAAkB;IACX,qBAAI,GAAX,UAAY,OAAsB,EAAE,OAAsB;QAAtB,wBAAA,EAAA,YAAsB;QACxD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;;;OASG;IACI,2BAAU,GAAjB,cAA4B,OAAO,CAAC,CAAC;IAErC;;;;OAIG;IACO,6BAAY,GAAtB;QACE,OAAO,SAAS,CAAC;IACnB,CAAC;IArPsB,aAAM,GAAG,WAAW,CAAC;IACrB,WAAI,GAAW,IAAI,CAAC;IAqP7C,aAAC;CAAA,AAvPD,IAuPC;AAGC,wBAAM"} \ No newline at end of file diff --git a/lib/Loggers/ServerLogger.d.ts b/lib/Loggers/ServerLogger.d.ts index b7bf8bc..2a9fece 100644 --- a/lib/Loggers/ServerLogger.d.ts +++ b/lib/Loggers/ServerLogger.d.ts @@ -5,7 +5,7 @@ import * as connect from "connect"; import { IncomingMessage, ServerResponse } from "http"; import { WebApp } from "meteor/webapp"; -import { IContext } from "../IContext"; +import { IContext, IDetails } from "../IContext"; import * as LogLevel from "../LogLevel"; import { IStrategy } from "../Strategies/IStrategy"; import { ILogger } from "./ILogger"; @@ -110,7 +110,7 @@ declare class ServerLogger extends Logger implements ILogger { /** * @inheritDoc */ - log(level: LogLevel.Levels, message: string, rawContext: IContext): void; + log(level: LogLevel.Levels, message: string, rawContext: IDetails): void; /** * Extended syntax for log() method. * diff --git a/lib/Loggers/ServerLogger.js b/lib/Loggers/ServerLogger.js index 2ab1b1c..b02a10f 100644 --- a/lib/Loggers/ServerLogger.js +++ b/lib/Loggers/ServerLogger.js @@ -211,7 +211,7 @@ var ServerLogger = /** @class */ (function (_super) { */ ServerLogger.prototype.defaultContext = function (initialContext, source) { var _a; - var cx1 = __assign((_a = {}, _a[IContext_1.HOST_KEY] = this._getHostname(), _a[IContext_1.SOURCE_KEY] = source, _a), initialContext); + var cx1 = __assign((_a = {}, _a[IContext_1.KEY_HOST] = this._getHostname(), _a[IContext_1.KEY_SOURCE] = source, _a), initialContext); Logger_1.Logger.stamp(cx1, "log", this.side); return cx1; }; @@ -256,10 +256,10 @@ var ServerLogger = /** @class */ (function (_super) { if (_this.logRequestHeaders) { context.requestHeaders = req.headers; } - var _a = IContext_1.DETAILS_KEY, details = context[_a], + var _a = IContext_1.KEY_DETAILS, details = context[_a], // tslint:disable-next-line nonDetails = __rest(context, [typeof _a === "symbol" ? _a : _a + ""]); - _this.logExtended(level, message, nonDetails, ClientLogger_1.ClientLogger.side); + _this.logExtended(level, message, nonDetails, ClientLogger_1.ClientSide); res.statusCode = 200; result = ""; } @@ -312,7 +312,7 @@ var ServerLogger = /** @class */ (function (_super) { */ ServerLogger.prototype.logMethod = function (_a) { var _b = _a.level, level = _b === void 0 ? LogLevel.INFO : _b, _c = _a.message, message = _c === void 0 ? "" : _c, _d = _a.context, context = _d === void 0 ? {} : _d; - this.logExtended(level, message, context, ClientLogger_1.ClientLogger.side); + this.logExtended(level, message, context, ClientLogger_1.ClientSide); }; /** * Sets up the Connect routing within the Meteor webapp component. diff --git a/lib/Loggers/ServerLogger.js.map b/lib/Loggers/ServerLogger.js.map index 5afe524..08db140 100644 --- a/lib/Loggers/ServerLogger.js.map +++ b/lib/Loggers/ServerLogger.js.map @@ -1 +1 @@ -{"version":3,"file":"ServerLogger.js","sourceRoot":"","sources":["../../src/Loggers/ServerLogger.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMH,8CAA8C;AAC9C,qCAAyB;AACzB,oDAA8B;AAC9B,yCAA6B;AAC7B,mBAAmB;AACnB,wCAAyE;AACzE,oDAAwC;AAExC,+CAA4C;AAE5C,mCAAgC;AAgBhC,IAAM,IAAI,GAAG,QAAQ,CAAC;AAoUZ,0BAAU;AAlUpB;;;;;;GAMG;AACH;IAA2B,gCAAM;IA0F/B,uCAAuC;IACvC;;;;;;;;;;;;OAYG;IACH,sBACE,QAAmB,EACZ,MAA6B,EACpC,UAAmD;;QAD5C,uBAAA,EAAA,aAA6B;QACpC,2BAAA,EAAA,eAAmD;QAHrD,YAKE,kBAAM,QAAQ,CAAC,SA+BhB;QAlCQ,YAAM,GAAN,MAAM,CAAuB;QA1B/B,kBAAY,GAAY,IAAI,CAAC;QAC7B,uBAAiB,GAAY,IAAI,CAAC;QAElC,qBAAe,GAAW,EAAE,CAAC;QAE7B,eAAS,GAAW,SAAS,CAAC;QACrC,kCAAkC;QAC3B,UAAI,GAAG,QAAQ,CAAC;QAChB,aAAO,GAAY,KAAK,CAAC;QAsB9B,KAAI,CAAC,MAAM,GAAG,iBAAO,CAAC,MAAM,CAAC;QAC7B,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAM,iBAAiB,GAAuC;YAC5D,YAAY,EAAE,IAAI;YAClB,iBAAiB,EAAE,IAAI;YACvB,8DAA8D;YAC9D,eAAe,EAAE,EAAE;YACnB,SAAS,EAAE,SAAS;Y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AE,OAAO,EAAE,2BAAY,CAAC,IAAI,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;;OAOG;IACI,mCAAY,GAAnB,UAAoB,MAAsB,EAAE,SAAiB;QAC3D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAqB,SAAS,QAAK,CAAC,CAAC;aACxD;YACD,IAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YACxC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SACjE;aAAM;YACL,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA4B,SAAS,QAAK,CAAC,CAAC;aAC/D;SACF;IACH,CAAC;IAED;;OAEG;IACO,mCAAY,GAAtB;QACE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;SAC/B;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IACH,mBAAC;AAAD,CAAC,AAtTD,CAA2B,eAAM,GAsThC;AAIC,oCAAY"} \ No newline at end of file +{"version":3,"file":"ServerLogger.js","sourceRoot":"","sources":["../../src/Loggers/ServerLogger.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMH,8CAA8C;AAC9C,qCAAyB;AACzB,oDAA8B;AAC9B,yCAA6B;AAC7B,mBAAmB;AACnB,wCAMqB;AACrB,oDAAwC;AAExC,+CAA0C;AAE1C,mCAAgC;AAgBhC,IAAM,IAAI,GAAG,QAAQ,CAAC;AAo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O,EAAE;gBAChB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA4B,SAAS,QAAK,CAAC,CAAC;aAC/D;SACF;IACH,CAAC;IAED;;OAEG;IACO,mCAAY,GAAtB;QACE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;SAC/B;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IACH,mBAAC;AAAD,CAAC,AAtTD,CAA2B,eAAM,GAsThC;AAIC,oCAAY"} \ No newline at end of file diff --git a/lib/Loggers/index.d.ts b/lib/Loggers/index.d.ts index ca9d308..21f8536 100644 --- a/lib/Loggers/index.d.ts +++ b/lib/Loggers/index.d.ts @@ -1,21 +1,22 @@ +import { IContext, IDetails, ITimestamps, KEY_DETAILS, KEY_HOST, KEY_SOURCE, KEY_TS } from "../IContext"; import InvalidArgumentException from "../InvalidArgumentException"; import * as LogLevel from "../LogLevel"; import { ClientLogger } from "./ClientLogger"; +import { ILogger } from "./ILogger"; import { Logger } from "./Logger"; import { ServerLogger } from "./ServerLogger"; import { BrowserProcessor } from "../Processors/BrowserProcessor"; -import MeteorUserProcessor from "../Processors/MeteorUserProcessor"; -import ProcessorBase from "../Processors/ProcessorBase"; -import RoutingProcessor from "../Processors/RoutingProcessor"; -import LeveledStrategy from "../Strategies/LeveledStrategy"; -import StrategyBase from "../Strategies/StrategyBase"; -import TrivialStrategy from "../Strategies/TrivialStrategy"; -import ConsoleSender from "../Senders/ConsoleSender"; -import MeteorClientHttpSender from "../Senders/MeteorClientHttpSender"; -import MeteorClientMethodSender from "../Senders/MeteorClientMethodSender"; -import MongodbSender from "../Senders/MongodbSender"; -import NullSender from "../Senders/NullSender"; -import { SenderBase } from "../Senders/SenderBase"; -import TeeSender from "../Senders/TeeSender"; +import { MeteorUserProcessor } from "../Processors/MeteorUserProcessor"; +import { ProcessorBase } from "../Processors/ProcessorBase"; +import { RoutingProcessor } from "../Processors/RoutingProcessor"; +import { LeveledStrategy } from "../Strategies/LeveledStrategy"; +import { StrategyBase } from "../Strategies/StrategyBase"; +import { TrivialStrategy } from "../Strategies/TrivialStrategy"; +import { ConsoleSender } from "../Senders/ConsoleSender"; +import { MeteorClientHttpSender } from "../Senders/MeteorClientHttpSender"; +import { MeteorClientMethodSender } from "../Senders/MeteorClientMethodSender"; +import { MongodbSender } from "../Senders/MongodbSender"; +import { NullSender } from "../Senders/NullSender"; +import { TeeSender } from "../Senders/TeeSender"; declare const SyslogSender: any; -export { InvalidArgumentException, LogLevel, Logger, ClientLogger, ServerLogger, ProcessorBase, BrowserProcessor, MeteorUserProcessor, RoutingProcessor, StrategyBase, LeveledStrategy, TrivialStrategy, SenderBase, NullSender, ConsoleSender, MeteorClientHttpSender, MeteorClientMethodSender, MongodbSender, SyslogSender, TeeSender, }; +export { IContext, IDetails, ITimestamps, KEY_DETAILS, KEY_HOST, KEY_SOURCE, KEY_TS, InvalidArgumentException, LogLevel, ILogger, Logger, ClientLogger, ServerLogger, ProcessorBase, BrowserProcessor, MeteorUserProcessor, RoutingProcessor, StrategyBase, LeveledStrategy, TrivialStrategy, NullSender, ConsoleSender, MeteorClientHttpSender, MeteorClientMethodSender, MongodbSender, SyslogSender, TeeSender, }; diff --git a/lib/Loggers/index.js b/lib/Loggers/index.js index c9b276e..8fc83f1 100644 --- a/lib/Loggers/index.js +++ b/lib/Loggers/index.js @@ -10,6 +10,11 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); +var IContext_1 = require("../IContext"); +exports.KEY_DETAILS = IContext_1.KEY_DETAILS; +exports.KEY_HOST = IContext_1.KEY_HOST; +exports.KEY_SOURCE = IContext_1.KEY_SOURCE; +exports.KEY_TS = IContext_1.KEY_TS; var InvalidArgumentException_1 = __importDefault(require("../InvalidArgumentException")); exports.InvalidArgumentException = InvalidArgumentException_1.default; var LogLevel = __importStar(require("../LogLevel")); @@ -22,32 +27,30 @@ var ServerLogger_1 = require("./ServerLogger"); exports.ServerLogger = ServerLogger_1.ServerLogger; var BrowserProcessor_1 = require("../Processors/BrowserProcessor"); exports.BrowserProcessor = BrowserProcessor_1.BrowserProcessor; -var MeteorUserProcessor_1 = __importDefault(require("../Processors/MeteorUserProcessor")); -exports.MeteorUserProcessor = MeteorUserProcessor_1.default; -var ProcessorBase_1 = __importDefault(require("../Processors/ProcessorBase")); -exports.ProcessorBase = ProcessorBase_1.default; -var RoutingProcessor_1 = __importDefault(require("../Processors/RoutingProcessor")); -exports.RoutingProcessor = RoutingProcessor_1.default; -var LeveledStrategy_1 = __importDefault(require("../Strategies/LeveledStrategy")); -exports.LeveledStrategy = LeveledStrategy_1.default; -var StrategyBase_1 = __importDefault(require("../Strategies/StrategyBase")); -exports.StrategyBase = StrategyBase_1.default; -var TrivialStrategy_1 = __importDefault(require("../Strategies/TrivialStrategy")); -exports.TrivialStrategy = TrivialStrategy_1.default; -var ConsoleSender_1 = __importDefault(require("../Senders/ConsoleSender")); -exports.ConsoleSender = ConsoleSender_1.default; -var MeteorClientHttpSender_1 = __importDefault(require("../Senders/MeteorClientHttpSender")); -exports.MeteorClientHttpSender = MeteorClientHttpSender_1.default; -var MeteorClientMethodSender_1 = __importDefault(require("../Senders/MeteorClientMethodSender")); -exports.MeteorClientMethodSender = MeteorClientMethodSender_1.default; -var MongodbSender_1 = __importDefault(require("../Senders/MongodbSender")); -exports.MongodbSender = MongodbSender_1.default; -var NullSender_1 = __importDefault(require("../Senders/NullSender")); -exports.NullSender = NullSender_1.default; -var SenderBase_1 = require("../Senders/SenderBase"); -exports.SenderBase = SenderBase_1.SenderBase; -var TeeSender_1 = __importDefault(require("../Senders/TeeSender")); -exports.TeeSender = TeeSender_1.default; +var MeteorUserProcessor_1 = require("../Processors/MeteorUserProcessor"); +exports.MeteorUserProcessor = MeteorUserProcessor_1.MeteorUserProcessor; +var ProcessorBase_1 = require("../Processors/ProcessorBase"); +exports.ProcessorBase = ProcessorBase_1.ProcessorBase; +var RoutingProcessor_1 = require("../Processors/RoutingProcessor"); +exports.RoutingProcessor = RoutingProcessor_1.RoutingProcessor; +var LeveledStrategy_1 = require("../Strategies/LeveledStrategy"); +exports.LeveledStrategy = LeveledStrategy_1.LeveledStrategy; +var StrategyBase_1 = require("../Strategies/StrategyBase"); +exports.StrategyBase = StrategyBase_1.StrategyBase; +var TrivialStrategy_1 = require("../Strategies/TrivialStrategy"); +exports.TrivialStrategy = TrivialStrategy_1.TrivialStrategy; +var ConsoleSender_1 = require("../Senders/ConsoleSender"); +exports.ConsoleSender = ConsoleSender_1.ConsoleSender; +var MeteorClientHttpSender_1 = require("../Senders/MeteorClientHttpSender"); +exports.MeteorClientHttpSender = MeteorClientHttpSender_1.MeteorClientHttpSender; +var MeteorClientMethodSender_1 = require("../Senders/MeteorClientMethodSender"); +exports.MeteorClientMethodSender = MeteorClientMethodSender_1.MeteorClientMethodSender; +var MongodbSender_1 = require("../Senders/MongodbSender"); +exports.MongodbSender = MongodbSender_1.MongodbSender; +var NullSender_1 = require("../Senders/NullSender"); +exports.NullSender = NullSender_1.NullSender; +var TeeSender_1 = require("../Senders/TeeSender"); +exports.TeeSender = TeeSender_1.TeeSender; /* modern-syslog is not usable on the client side, because it fails to load * its compiled binary dependency, hence the dynamic require and tslint disable. * @@ -55,7 +58,7 @@ exports.TeeSender = TeeSender_1.default; */ var SyslogSender = Meteor.isServer // tslint:disable-next-line - ? require("../Senders/SyslogSender").default - : NullSender_1.default; + ? require("../Senders/SyslogSender").SyslogSender + : NullSender_1.NullSender; exports.SyslogSender = SyslogSender; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/Loggers/index.js.map b/lib/Loggers/index.js.map index 3d5cdc4..0bb0b85 100644 --- a/lib/Loggers/index.js.map +++ b/lib/Loggers/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Loggers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AA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C+D,qBAAU,CA0C/D;AACV,iBA3C2E,iBAAM,CA2C3E;AA1CR,yFAAmE;AA4CjE,mCA5CK,kCAAwB,CA4CL;AA3C1B,oDAAwC;AA4CtC,4BAAQ;AA1CV,+CAA8C;AA+C5C,uBA/CO,2BAAY,CA+CP;AA7Cd,mCAAkC;AA4ChC,iBA5CO,eAAM,CA4CP;AA3CR,+CAA8C;AA6C5C,uBA7CO,2BAAY,CA6CP;AA3Cd,mEAAkE;AA+ChE,2BA/CO,mCAAgB,CA+CP;AA9ClB,yEAAwE;AA+CtE,8BA/CO,yCAAmB,CA+CP;AA9CrB,6DAA4D;AA4C1D,wBA5CO,6BAAa,CA4CP;AA3Cf,mEAAkE;AA8ChE,2BA9CO,mCAAgB,CA8CP;AA5ClB,iEAAgE;AAgD9D,0BAhDO,iCAAe,CAgDP;AA/CjB,2DAA0D;AA8CxD,uBA9CO,2BAAY,CA8CP;AA7Cd,iEAAgE;AA+C9D,0BA/CO,iCAAe,CA+CP;AA7CjB,0DAAyD;AAgDvD,wBAhDO,6BAAa,CAgDP;AA/Cf,4EAA2E;AAgDzE,iCAhDO,+CAAsB,CAgDP;AA/CxB,gFAA+E;AAgD7E,mCAhDO,mDAAwB,CAgDP;AA/C1B,0DAAyD;AAgDvD,wBAhDO,6BAAa,CAgDP;AA/Cf,oDAAmD;AA2CjD,qBA3CO,uBAAU,CA2CP;AA1CZ,kDAAiD;AAgD/C,oBAhDO,qBAAS,CAgDP;AA9CX;;;;GAIG;AACH,IAAM,YAAY,GAAG,MAAM,CAAC,QAAQ;IAClC,2BAA2B;IAC3B,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC,YAAY;IACjD,CAAC,CAAC,uBAAU,CAAC;AAqCb,oCAAY"} \ No newline at end of file diff --git a/lib/Processors/BrowserProcessor.d.ts b/lib/Processors/BrowserProcessor.d.ts index 93a1bbc..4d37c46 100644 --- a/lib/Processors/BrowserProcessor.d.ts +++ b/lib/Processors/BrowserProcessor.d.ts @@ -2,6 +2,8 @@ * @fileOverview Browser Processor class. */ import { IContext } from "../IContext"; +import { IProcessor } from "./IProcessor"; +import { ProcessorBase } from "./ProcessorBase"; interface IMemoryInfo { jsHeapSizeLimit: number; totalJSHeapSize: number; @@ -32,12 +34,19 @@ interface INavigator { * * @extends ProcessorBase */ -declare const BrowserProcessor: { - new (nav: INavigator, win: IWindow): { - navigator: INavigator; - window: IWindow; - /** @inheritDoc */ - process(context: object): IContext; - }; -}; +declare class BrowserProcessor extends ProcessorBase implements IProcessor { + navigator: INavigator; + window: IWindow; + /** + * ProcessorBase ensures it is not being built outside a browser. + * + * @param {object} nav + * window.Navigator. + * @param {object} win + * window. + */ + constructor(nav: INavigator, win: IWindow); + /** @inheritDoc */ + process(context: object): IContext; +} export { BrowserProcessor, IBrowserInfo, IMemoryInfo, INavigator, IPerformance, IWindow, }; diff --git a/lib/Processors/BrowserProcessor.js b/lib/Processors/BrowserProcessor.js index 295d346..8c1b008 100644 --- a/lib/Processors/BrowserProcessor.js +++ b/lib/Processors/BrowserProcessor.js @@ -23,11 +23,8 @@ var __assign = (this && this.__assign) || function () { }; return __assign.apply(this, arguments); }; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); -var ProcessorBase_1 = __importDefault(require("./ProcessorBase")); +var ProcessorBase_1 = require("./ProcessorBase"); /** * Adds browser related information to an event context. * @@ -37,7 +34,7 @@ var ProcessorBase_1 = __importDefault(require("./ProcessorBase")); * @extends ProcessorBase */ var BrowserProcessor = /** @class */ (function (_super) { - __extends(class_1, _super); + __extends(BrowserProcessor, _super); /** * ProcessorBase ensures it is not being built outside a browser. * @@ -46,7 +43,7 @@ var BrowserProcessor = /** @class */ (function (_super) { * @param {object} win * window. */ - function class_1(nav, win) { + function BrowserProcessor(nav, win) { var _this = _super.call(this) || this; var actualNav = nav || (typeof navigator === "object" && navigator); var actualWin = win || (typeof window === "object" && window); @@ -58,7 +55,7 @@ var BrowserProcessor = /** @class */ (function (_super) { return _this; } /** @inheritDoc */ - class_1.prototype.process = function (context) { + BrowserProcessor.prototype.process = function (context) { var unknown = "unknown"; var browserDefaults = { platform: unknown, @@ -85,7 +82,7 @@ var BrowserProcessor = /** @class */ (function (_super) { : {}; return result; }; - return class_1; -}(ProcessorBase_1.default)); + return BrowserProcessor; +}(ProcessorBase_1.ProcessorBase)); exports.BrowserProcessor = BrowserProcessor; //# sourceMappingURL=BrowserProcessor.js.map \ No newline at end of file diff --git a/lib/Processors/BrowserProcessor.js.map b/lib/Processors/BrowserProcessor.js.map index d76b82c..8155161 100644 --- a/lib/Processors/BrowserProcessor.js.map +++ b/lib/Processors/BrowserProcessor.js.map @@ -1 +1 @@ -{"version":3,"file":"BrowserProcessor.js","sourceRoot":"","sources":["../../src/Processors/BrowserProcessor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,kEAA4C;AA8B5C;;;;;;;GAOG;AACH,IAAM,gBAAgB;IAAiB,2BAAa;IAIlD;;;;;;;OAOG;IACH,iBAAY,GAAe,EAAE,GAAY;QAAzC,YACE,iBAAO,SAUR;QATC,IAAM,SAAS,GAAG,GAAG,IAAI,CAAC,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,CAAC;QACtE,IAAM,SAAS,GAAG,GAAG,IAAI,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,CAAC;QAEhE,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE;YAC9F,MAAM,IAAI,cAAc,CAAC,sDAAsD,CAAC,CAAC;SAClF;QAED,KAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,KAAI,CAAC,MAAM,GAAG,SAAS,CAAC;;IAC1B,CAAC;IAED,kBAAkB;IACX,yBAAO,GAAd,UAAe,OAAe;QAC5B,IAAM,OAAO,GAAG,SAAS,CAAC;QAC1B,IAAM,eAAe,GAAiB;YACpC,QAAQ,EAAE,OAAO;YACjB,SAAS,EAAE,OAAO;SACnB,CAAC;QAEF,6EAA6E;QAC7E,IAAM,MAAM,cACR,OAAO,aACL,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,IACjC,eAAe,KAEjB,OAAO,CACX,CAAC;QAEJ,4EAA4E;QAC5E,KAAK,IAAM,GAAG,IAAI,eAAe,EAAE;YACjC,IAAI,eAAe,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;gBACvC,MAAM,CAAC,OAAO,CAAC,GAAyB,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;oBAC7D,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;oBACrB,CAAC,CAAC,eAAe,CAAC,GAAyB,CAAC,CAAC;aAChD;SACF;QAED,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;YACtF,CAAC,CAAC;gBACE,MAAM,EAAE;oBACN,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,eAAe;oBAC/D,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,eAAe;oBAC/D,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,cAAc;iBAC9D;aACF;YACH,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,cAAC;AAAD,CAAC,AA/DwB,CAAc,uBAAa,EA+DnD,CAAC;AAGA,4CAAgB"} \ No newline at end of file +{"version":3,"file":"BrowserProcessor.js","sourceRoot":"","sources":["../../src/Processors/BrowserProcessor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,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AC,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;YACtF,CAAC,CAAC;gBACE,MAAM,EAAE;oBACN,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,eAAe;oBAC/D,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,eAAe;oBAC/D,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,cAAc;iBAC9D;aACF;YACH,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,uBAAC;AAAD,CAAC,AA/DD,CAA+B,6BAAa,GA+D3C;AAGC,4CAAgB"} \ No newline at end of file diff --git a/lib/Processors/MeteorUserProcessor.d.ts b/lib/Processors/MeteorUserProcessor.d.ts index 89e9dc5..e289e02 100644 --- a/lib/Processors/MeteorUserProcessor.d.ts +++ b/lib/Processors/MeteorUserProcessor.d.ts @@ -1,4 +1,9 @@ /** global: Package */ +/** + * @fileOverview Meteor user Processor class. + */ +import { IProcessor } from "./IProcessor"; +import { ProcessorBase } from "./ProcessorBase"; import User = Meteor.User; import { IContext } from "../IContext"; /** @@ -6,53 +11,58 @@ import { IContext } from "../IContext"; * * @extends ProcessorBase */ -declare const MeteorUserProcessor: { - new (meteor?: typeof Meteor, postProcess?: ((r: {}) => {}) | null): { - platform: string; - userCache: { - [key: string]: object; - }; - meteor: typeof Meteor; - postProcess: ((r: {}) => {}) | null; - /** - * Return a default empty user, with required fill set to empty values. - * - * @param {String} id - * Optional. A user id. - * @returns {Object} - * An account object initialized for anonymous. - * - */ - getAnonymousAccount(id?: number): { - _id: number; - emails: never[]; - profile: {}; - services: {}; - username: null; - }; - /** - * Get this.userId on the logger caller. - * - * Builds on v8 internals, so only works server-side (nodejs) or browsers with - * a v8 engine. - * - * @TODO Assumes Error.stackTraceLimit is sufficient: default is 10, it - * usually needs only 8 to climb up to the log caller. Maybe - * check/increase/restore for safety ? - * - * @returns - * The user id. Undefined when not logged-in. - */ - v8getUserId(): string | undefined; - /** - * Return the current user information, as far as possible. - * - * @returns {Object} - * A user object, possibly for an anonymous account. - */ - getUser(): User; - /** @inheritdoc */ - process(context: IContext): IContext; +declare class MeteorUserProcessor extends ProcessorBase implements IProcessor { + meteor: typeof Meteor; + postProcess: ((r: {}) => {}) | null; + platform: string; + userCache: { + [key: string]: object; + }; + /** + * @param meteor + * The Meteor service. + * @param postProcess + * Optional. A post-process callback to be invoked after the main process(). + */ + constructor(meteor?: typeof Meteor, postProcess?: ((r: {}) => {}) | null); + /** + * Return a default empty user, with required fill set to empty values. + * + * @param {String} id + * Optional. A user id. + * @returns {Object} + * An account object initialized for anonymous. + * + */ + getAnonymousAccount(id?: number): { + _id: number; + emails: never[]; + profile: {}; + services: {}; + username: null; }; -}; -export default MeteorUserProcessor; + /** + * Get this.userId on the logger caller. + * + * Builds on v8 internals, so only works server-side (nodejs) or browsers with + * a v8 engine. + * + * @TODO Assumes Error.stackTraceLimit is sufficient: default is 10, it + * usually needs only 8 to climb up to the log caller. Maybe + * check/increase/restore for safety ? + * + * @returns + * The user id. Undefined when not logged-in. + */ + v8getUserId(): string | undefined; + /** + * Return the current user information, as far as possible. + * + * @returns {Object} + * A user object, possibly for an anonymous account. + */ + getUser(): User; + /** @inheritdoc */ + process(context: IContext): IContext; +} +export { MeteorUserProcessor, }; diff --git a/lib/Processors/MeteorUserProcessor.js b/lib/Processors/MeteorUserProcessor.js index 6daf0bd..8d247c2 100644 --- a/lib/Processors/MeteorUserProcessor.js +++ b/lib/Processors/MeteorUserProcessor.js @@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var ProcessorBase_1 = __importDefault(require("./ProcessorBase")); +var ProcessorBase_1 = require("./ProcessorBase"); var callsite_1 = __importDefault(require("callsite")); var IContext_1 = require("../IContext"); /** @@ -36,14 +36,14 @@ var IContext_1 = require("../IContext"); * @extends ProcessorBase */ var MeteorUserProcessor = /** @class */ (function (_super) { - __extends(class_1, _super); + __extends(MeteorUserProcessor, _super); /** * @param meteor * The Meteor service. * @param postProcess * Optional. A post-process callback to be invoked after the main process(). */ - function class_1(meteor, postProcess) { + function MeteorUserProcessor(meteor, postProcess) { if (meteor === void 0) { meteor = Meteor; } if (postProcess === void 0) { postProcess = null; } var _this = _super.call(this) || this; @@ -82,7 +82,7 @@ var MeteorUserProcessor = /** @class */ (function (_super) { * An account object initialized for anonymous. * */ - class_1.prototype.getAnonymousAccount = function (id) { + MeteorUserProcessor.prototype.getAnonymousAccount = function (id) { if (id === void 0) { id = 0; } return { _id: id, @@ -105,7 +105,7 @@ var MeteorUserProcessor = /** @class */ (function (_super) { * @returns * The user id. Undefined when not logged-in. */ - class_1.prototype.v8getUserId = function () { + MeteorUserProcessor.prototype.v8getUserId = function () { var e_1, _a; var stackValue = callsite_1.default(); var state = "below-logger"; @@ -152,7 +152,7 @@ var MeteorUserProcessor = /** @class */ (function (_super) { * @returns {Object} * A user object, possibly for an anonymous account. */ - class_1.prototype.getUser = function () { + MeteorUserProcessor.prototype.getUser = function () { var result; // We ruled out other platforms beyond client and server in constructor. if (this.meteor.isClient) { @@ -187,7 +187,7 @@ var MeteorUserProcessor = /** @class */ (function (_super) { return result; }; /** @inheritdoc */ - class_1.prototype.process = function (context) { + MeteorUserProcessor.prototype.process = function (context) { var _a; var user = this.getUser(); // Cannot delete property from undefined or null. @@ -198,7 +198,7 @@ var MeteorUserProcessor = /** @class */ (function (_super) { // mobile information, a straight server-side log context is not rebuilt by // a call to logExtended, so it needs to be set directly in place under a // platform key. - var userContext = (context[IContext_1.SOURCE_KEY] === this.platform) + var userContext = (context[IContext_1.KEY_SOURCE] === this.platform) ? (_a = {}, _a[this.platform] = { user: user }, _a) : { user: user }; var result = Object.assign({}, context, userContext); if (this.postProcess) { @@ -206,7 +206,7 @@ var MeteorUserProcessor = /** @class */ (function (_super) { } return result; }; - return class_1; -}(ProcessorBase_1.default)); -exports.default = MeteorUserProcessor; + return MeteorUserProcessor; +}(ProcessorBase_1.ProcessorBase)); +exports.MeteorUserProcessor = MeteorUserProcessor; //# sourceMappingURL=MeteorUserProcessor.js.map \ No newline at end of file diff --git a/lib/Processors/MeteorUserProcessor.js.map b/lib/Processors/MeteorUserProcessor.js.map index 4f89fd6..45daee1 100644 --- a/lib/Processors/MeteorUserProcessor.js.map +++ b/lib/Processors/MeteorUserProcessor.js.map @@ -1 +1 @@ -{"version":3,"file":"MeteorUserProcessor.js","sourceRoot":"","sources":["../../src/Processors/MeteorUserProcessor.ts"],"names":[],"mappings":";AAAA,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOtB,kEAA4C;AAE5C,sDAA6B;AAE7B,wCAAiD;AAcjD;;;;GAIG;AACH,IAAM,mBAAmB;IAAiB,2BAAa;IAIrD;;;;;OAKG;IACH,iBAAmB,MAAe,EAAS,WAA0C;QAAlE,uBAAA,EAAA,eAAe;QAAS,4BAAA,EAAA,kBAA0C;QAArF,YACE,iBAAO,SAsBR;QAvBkB,YAAM,GAAN,MAAM,CAAS;QAAS,iBAAW,GAAX,WAAW,CAA+B;QAEnF,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;SACpE;QACD,IAAI,MAAM,CAAC,QAAQ,EAAE;YACnB,KAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,UAAU,EAAE;gBAC/D,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;aACxF;SACF;aAAM,IAAI,MAAM,CAAC,QAAQ,EAAE;YAC1B,KAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACzB,IAAM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AAM,GAAG,IAAI,CAAC;aACf;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,kBAAkB;IACX,yBAAO,GAAd,UAAe,OAAiB;;QAC9B,IAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAE5B,iDAAiD;QACjD,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;YACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;SAC7B;QAED,yEAAyE;QACzE,2EAA2E;QAC3E,yEAAyE;QACzE,gBAAgB;QAChB,IAAM,WAAW,GAAG,CAAC,OAAO,CAAC,qBAAU,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC;YACzD,CAAC,WAAG,GAAC,IAAI,CAAC,QAAQ,IAAG,EAAE,IAAI,MAAA,EAAE,MAC7B,CAAC,CAAC,EAAE,IAAI,MAAA,EAAE,CAAC;QACb,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;QAErD,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;SACnC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,cAAC;AAAD,CAAC,AArK2B,CAAc,uBAAa,EAqKtD,CAAC;AAEF,kBAAe,mBAAmB,CAAC"} \ No newline at end of file +{"version":3,"file":"MeteorUserProcessor.js","sourceRoot":"","sources":["../../src/Processors/MeteorUserProcessor.ts"],"names":[],"mappings":";AAAA,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOtB,iDAAgD;AAEhD,sDAA6B;AAE7B,wCAAiD;AAcjD;;;;GAIG;AACH;IAAkC,uCAAa;IAI7C;;;;;OAKG;IACH,6BAAmB,MAAe,EAAS,WAA0C;QAAlE,uBAAA,EAAA,eAAe;QAAS,4BAAA,EAAA,kBAA0C;QAArF,YACE,iBAAO,SAsBR;QAvBk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C;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,0BAAC;AAAD,CAAC,AArKD,CAAkC,6BAAa,GAqK9C;AAGC,kDAAmB"} \ No newline at end of file diff --git a/lib/Processors/ProcessorBase.d.ts b/lib/Processors/ProcessorBase.d.ts index 1e07c8a..91bfcbb 100644 --- a/lib/Processors/ProcessorBase.d.ts +++ b/lib/Processors/ProcessorBase.d.ts @@ -2,15 +2,14 @@ * @fileOverview Base Processor class. */ import { IContext } from "../IContext"; +import { IProcessor } from "./IProcessor"; /** * An "abstract" processor base class. * * It exists only to document the processor interface. */ -declare const ProcessorBase: { - new (): { - /** @inheritDoc */ - process(context: IContext): IContext; - }; -}; -export default ProcessorBase; +declare class ProcessorBase implements IProcessor { + /** @inheritDoc */ + process(context: IContext): IContext; +} +export { ProcessorBase, }; diff --git a/lib/Processors/ProcessorBase.js b/lib/Processors/ProcessorBase.js index e50bc99..7627f4f 100644 --- a/lib/Processors/ProcessorBase.js +++ b/lib/Processors/ProcessorBase.js @@ -9,13 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true }); * It exists only to document the processor interface. */ var ProcessorBase = /** @class */ (function () { - function class_1() { + function ProcessorBase() { } /** @inheritDoc */ - class_1.prototype.process = function (context) { + ProcessorBase.prototype.process = function (context) { return context; }; - return class_1; + return ProcessorBase; }()); -exports.default = ProcessorBase; +exports.ProcessorBase = ProcessorBase; //# sourceMappingURL=ProcessorBase.js.map \ No newline at end of file diff --git a/lib/Processors/ProcessorBase.js.map b/lib/Processors/ProcessorBase.js.map index 7e01636..81814c0 100644 --- a/lib/Processors/ProcessorBase.js.map +++ b/lib/Processors/ProcessorBase.js.map @@ -1 +1 @@ -{"version":3,"file":"ProcessorBase.js","sourceRoot":"","sources":["../../src/Processors/ProcessorBase.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAKH;;;;GAIG;AACH,IAAM,aAAa;IAAG;IAKtB,CAAC;IAJC,kBAAkB;IACX,yBAAO,GAAd,UAAe,OAAiB;QAC9B,OAAO,OAAmB,CAAC;IAC7B,CAAC;IACH,cAAC;AAAD,CAAC,AALqB,GAKrB,CAAC;AAEF,kBAAe,aAAa,CAAC"} \ No newline at end of file +{"version":3,"file":"ProcessorBase.js","sourceRoot":"","sources":["../../src/Processors/ProcessorBase.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAKH;;;;GAIG;AACH;IAAA;IAKA,CAAC;IAJC,kBAAkB;IACX,+BAAO,GAAd,UAAe,OAAiB;QAC9B,OAAO,OAAmB,CAAC;IAC7B,CAAC;IACH,oBAAC;AAAD,CAAC,AALD,IAKC;AAGC,sCAAa"} \ No newline at end of file diff --git a/lib/Processors/RoutingProcessor.d.ts b/lib/Processors/RoutingProcessor.d.ts index 3b3da3f..e9f043f 100644 --- a/lib/Processors/RoutingProcessor.d.ts +++ b/lib/Processors/RoutingProcessor.d.ts @@ -2,23 +2,27 @@ * @fileOverview Routing Processor class. */ import { IContext } from "../IContext"; +import { IProcessor } from "./IProcessor"; +import { ProcessorBase } from "./ProcessorBase"; /** * RoutingProcessor adds route information to logs. * * @extends ProcessorBase */ -declare const RoutingProcessor: { - new (): { - /** - * Overwrite any previous routing information in context. - * - * @param {object} context - * The context object for a log event. - * - * @returns {object} - * The processed context object. - */ - process(context: IContext): IContext; - }; -}; -export default RoutingProcessor; +declare class RoutingProcessor extends ProcessorBase implements IProcessor { + /** + * Constructor ensures the processor is used in a browser context. + */ + constructor(); + /** + * Overwrite any previous routing information in context. + * + * @param {object} context + * The context object for a log event. + * + * @returns {object} + * The processed context object. + */ + process(context: IContext): IContext; +} +export { RoutingProcessor, }; diff --git a/lib/Processors/RoutingProcessor.js b/lib/Processors/RoutingProcessor.js index faf4bd2..1ff31f7 100644 --- a/lib/Processors/RoutingProcessor.js +++ b/lib/Processors/RoutingProcessor.js @@ -12,22 +12,19 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); -var ProcessorBase_1 = __importDefault(require("./ProcessorBase")); +var ProcessorBase_1 = require("./ProcessorBase"); /** * RoutingProcessor adds route information to logs. * * @extends ProcessorBase */ var RoutingProcessor = /** @class */ (function (_super) { - __extends(class_1, _super); + __extends(RoutingProcessor, _super); /** * Constructor ensures the processor is used in a browser context. */ - function class_1() { + function RoutingProcessor() { var _this = _super.call(this) || this; if (!window || !window.location) { throw new Error("Cannot provide route information without location information."); @@ -43,11 +40,11 @@ var RoutingProcessor = /** @class */ (function (_super) { * @returns {object} * The processed context object. */ - class_1.prototype.process = function (context) { + RoutingProcessor.prototype.process = function (context) { var result = Object.assign({}, context, { routing: { location: window.location } }); return result; }; - return class_1; -}(ProcessorBase_1.default)); -exports.default = RoutingProcessor; + return RoutingProcessor; +}(ProcessorBase_1.ProcessorBase)); +exports.RoutingProcessor = RoutingProcessor; //# sourceMappingURL=RoutingProcessor.js.map \ No newline at end of file diff --git a/lib/Processors/RoutingProcessor.js.map b/lib/Processors/RoutingProcessor.js.map index 303fda1..8967629 100644 --- a/lib/Processors/RoutingProcessor.js.map +++ b/lib/Processors/RoutingProcessor.js.map @@ -1 +1 @@ -{"version":3,"file":"RoutingProcessor.js","sourceRoot":"","sources":["../../src/Processors/RoutingProcessor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,kEAA4C;AAE5C;;;;GAIG;AACH,IAAM,gBAAgB;IAAiB,2BAAa;IAClD;;OAEG;IACH;QAAA,YACE,iBAAO,SAIR;QAHC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;SACnF;;IACH,CAAC;IAED;;;;;;;;OAQG;IACI,yBAAO,GAAd,UAAe,OAAiB;QAC9B,IAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACtF,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,cAAC;AAAD,CAAC,AAxBwB,CAAc,uBAAa,EAwBnD,CAAC;AAEF,kBAAe,gBAAgB,CAAC"} \ No newline at end of file +{"version":3,"file":"RoutingProcessor.js","sourceRoot":"","sources":["../../src/Processors/RoutingProcessor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,iDAAgD;AAEhD;;;;GAIG;AACH;IAA+B,oCAAa;IAC1C;;OAEG;IACH;QAAA,YACE,iBAAO,SAIR;QAHC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;SACnF;;IACH,CAAC;IAED;;;;;;;;OAQG;IACI,kCAAO,GAAd,UAAe,OAAiB;QAC9B,IAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACtF,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,uBAAC;AAAD,CAAC,AAxBD,CAA+B,6BAAa,GAwB3C;AAGC,4CAAgB"} \ No newline at end of file diff --git a/lib/Senders/ConsoleSender.d.ts b/lib/Senders/ConsoleSender.d.ts index bfcfce6..3278f5b 100644 --- a/lib/Senders/ConsoleSender.d.ts +++ b/lib/Senders/ConsoleSender.d.ts @@ -4,16 +4,15 @@ * Because this file is about actually using the console, it has to disable the * no-console rule. */ +import { IContext } from "../IContext"; import * as LogLevel from "../LogLevel"; +import { ISender } from "./ISender"; /** * ConsoleSender sends the log events it receives to the browser console. - * - * @extends SenderBase */ -declare const ConsoleSender: { - new (): { - /** @inheritDoc */ - send(level: LogLevel.Levels, message: string, context: object): void; - }; -}; -export default ConsoleSender; +declare class ConsoleSender implements ISender { + constructor(); + /** @inheritDoc */ + send(level: LogLevel.Levels, message: string, context: IContext): void; +} +export { ConsoleSender, }; diff --git a/lib/Senders/ConsoleSender.js b/lib/Senders/ConsoleSender.js index 90ad893..2f82011 100644 --- a/lib/Senders/ConsoleSender.js +++ b/lib/Senders/ConsoleSender.js @@ -6,19 +6,6 @@ * no-console rule. */ /* tslint:disable:no-console */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; @@ -28,17 +15,12 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); var LogLevel = __importStar(require("../LogLevel")); -var SenderBase_1 = require("./SenderBase"); /** * ConsoleSender sends the log events it receives to the browser console. - * - * @extends SenderBase */ -var ConsoleSender = /** @class */ (function (_super) { - __extends(class_1, _super); - function class_1() { - var _this = _super.call(this) || this; - // Checkint "if (!(console instanceof Console)" compiles, but fails to +var ConsoleSender = /** @class */ (function () { + function ConsoleSender() { + // Checking "if (!(console instanceof Console)" compiles, but fails to // execute during tests, which run in Node.JS in which Console is not a type // but only the name of the console constructor. Since checking // console.constructor.name is liable to fail in minified code, we need a @@ -54,10 +36,9 @@ var ConsoleSender = /** @class */ (function (_super) { throw new Error("Console property method " + method + " is not a function."); } }); - return _this; } /** @inheritDoc */ - class_1.prototype.send = function (level, message, context) { + ConsoleSender.prototype.send = function (level, message, context) { var methods = [ console.error, console.error, @@ -71,7 +52,7 @@ var ConsoleSender = /** @class */ (function (_super) { var method = methods[level].bind(console); method(LogLevel.Names[level], message, context); }; - return class_1; -}(SenderBase_1.SenderBase)); -exports.default = ConsoleSender; + return ConsoleSender; +}()); +exports.ConsoleSender = ConsoleSender; //# sourceMappingURL=ConsoleSender.js.map \ No newline at end of file diff --git a/lib/Senders/ConsoleSender.js.map b/lib/Senders/ConsoleSender.js.map index 51aa1cd..4afe5a1 100644 --- a/lib/Senders/ConsoleSender.js.map +++ b/lib/Senders/ConsoleSender.js.map @@ -1 +1 @@ -{"version":3,"file":"ConsoleSender.js","sourceRoot":"","sources":["../../src/Senders/ConsoleSender.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,+BAA+B;;;;;;;;;;;;;;;;;;;;;;AAE/B,oDAAwC;AAExC,2CAA0C;AAE1C;;;;GAIG;AACH,IAAM,aAAa;IAAiB,2BAAU;IAC5C;QAAA,YACE,iBAAO,SAiBR;QAhBC,sEAAsE;QACtE,4EAA4E;QAC5E,+DAA+D;QAC/D,yEAAyE;QACzE,gBAAgB;QAChB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YACrF,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;SAC3D;QACD,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,UAAC,MAAM;YAC9C,IAAI,OAAO,OAAO,CAAC,MAAuB,CAAC,KAAK,WAAW,EAAE;gBAC3D,MAAM,IAAI,KAAK,CAAC,+BAA6B,MAAM,MAAG,CAAC,CAAC;aACzD;YACD,IAAI,OAAO,CAAC,MAAuB,CAAC,CAAC,WAAW,CAAC,IAAI,KAAK,UAAU,EAAE;gBACpE,MAAM,IAAI,KAAK,CAAC,6BAA2B,MAAM,wBAAqB,CAAC,CAAC;aACzE;QACH,CAAC,CAAC,CAAC;;IACL,CAAC;IAED,kBAAkB;IACX,sBAAI,GAAX,UAAY,KAAsB,EAAE,OAAe,EAAE,OAAe;QAClE,IAAM,OAAO,GAAG;YACd,OAAO,CAAC,KAAK;YACb,OAAO,CAAC,KAAK;YACb,OAAO,CAAC,KAAK;YACb,OAAO,CAAC,KAAK;YACb,OAAO,CAAC,IAAI;YACZ,OAAO,CAAC,IAAI;YACZ,OAAO,CAAC,IAAI;YACZ,OAAO,CAAC,GAAG;SACZ,CAAC;QAEF,IAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IACH,cAAC;AAAD,CAAC,AArCqB,CAAc,uBAAU,EAqC7C,CAAC;AAEF,kBAAe,aAAa,CAAC"} \ No newline at end of file +{"version":3,"file":"ConsoleSender.js","sourceRoot":"","sources":["../../src/Senders/ConsoleSender.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,+BAA+B;;;;;;;;;AAG/B,oDAAwC;AAGxC;;GAEG;AACH;IACE;QACE,sEAAsE;QACtE,4EAA4E;QAC5E,+DAA+D;QAC/D,yEAAyE;QACzE,gBAAgB;QAChB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YACrF,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;SAC3D;QACD,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,UAAC,MAAM;YAC9C,IAAI,OAAO,OAAO,CAAC,MAAuB,CAAC,KAAK,WAAW,EAAE;gBAC3D,MAAM,IAAI,KAAK,CAAC,+BAA6B,MAAM,MAAG,CAAC,CAAC;aACzD;YACD,IAAI,OAAO,CAAC,MAAuB,CAAC,CAAC,WAAW,CAAC,IAAI,KAAK,UAAU,EAAE;gBACpE,MAAM,IAAI,KAAK,CAAC,6BAA2B,MAAM,wBAAqB,CAAC,CAAC;aACzE;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,kBAAkB;IACX,4BAAI,GAAX,UAAY,KAAsB,EAAE,OAAe,EAAE,OAAiB;QACpE,IAAM,OAAO,GAAG;YACd,OAAO,CAAC,KAAK;YACb,OAAO,CAAC,KAAK;YACb,OAAO,CAAC,KAAK;YACb,OAAO,CAAC,KAAK;YACb,OAAO,CAAC,IAAI;YACZ,OAAO,CAAC,IAAI;YACZ,OAAO,CAAC,IAAI;YACZ,OAAO,CAAC,GAAG;SACZ,CAAC;QAEF,IAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IACH,oBAAC;AAAD,CAAC,AApCD,IAoCC;AAGC,sCAAa"} \ No newline at end of file diff --git a/lib/Senders/ISender.d.ts b/lib/Senders/ISender.d.ts index 0dce7b0..d908d8c 100644 --- a/lib/Senders/ISender.d.ts +++ b/lib/Senders/ISender.d.ts @@ -1,3 +1,4 @@ +import { IContext } from "../IContext"; import * as LogLevel from "../LogLevel"; interface ISender { /** @@ -10,6 +11,6 @@ interface ISender { * @param context * A log event context object. */ - send(level: LogLevel.Levels, message: string, context: object): void; + send(level: LogLevel.Levels, message: string, context: IContext): void; } export { ISender, }; diff --git a/lib/Senders/MeteorClientHttpSender.d.ts b/lib/Senders/MeteorClientHttpSender.d.ts index e85fcda..65232a3 100644 --- a/lib/Senders/MeteorClientHttpSender.d.ts +++ b/lib/Senders/MeteorClientHttpSender.d.ts @@ -1,18 +1,22 @@ /** global: HTTP, Meteor */ +import { ISender } from "./ISender"; /** * MeteorClientHttpSender send data from the client to the server over HTTP. - * - * @extends SenderBase */ -declare const MeteorClientHttpSender: { - new (loggerUrl: string): { - http: typeof HTTP; - requestHeaders: { - [key: string]: string; - }; - loggerUrl: string; - /** @inheritDoc */ - send(level: number, message: string, context: object): void; +declare class MeteorClientHttpSender implements ISender { + loggerUrl: string; + http: typeof HTTP; + requestHeaders: { + [key: string]: string; }; -}; -export default MeteorClientHttpSender; + /** + * @constructor + * + * @param {String} loggerUrl + * The absolute URL of the logger server. Usually /logger on the Meteor app. + */ + constructor(loggerUrl: string); + /** @inheritDoc */ + send(level: number, message: string, context: object): void; +} +export { MeteorClientHttpSender, }; diff --git a/lib/Senders/MeteorClientHttpSender.js b/lib/Senders/MeteorClientHttpSender.js index c94b067..fd52ec8 100644 --- a/lib/Senders/MeteorClientHttpSender.js +++ b/lib/Senders/MeteorClientHttpSender.js @@ -1,18 +1,5 @@ "use strict"; /** global: HTTP, Meteor */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -21,14 +8,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); * @fileOverview Meteor Client HTTP Sender class. */ var NullFn_1 = __importDefault(require("../NullFn")); -var SenderBase_1 = require("./SenderBase"); /** * MeteorClientHttpSender send data from the client to the server over HTTP. - * - * @extends SenderBase */ -var MeteorClientHttpSender = /** @class */ (function (_super) { - __extends(class_1, _super); +var MeteorClientHttpSender = /** @class */ (function () { // noinspection JSClassNamingConvention /** * @constructor @@ -36,23 +19,21 @@ var MeteorClientHttpSender = /** @class */ (function (_super) { * @param {String} loggerUrl * The absolute URL of the logger server. Usually /logger on the Meteor app. */ - function class_1(loggerUrl) { - var _this = _super.call(this) || this; - _this.loggerUrl = loggerUrl; + function MeteorClientHttpSender(loggerUrl) { + this.loggerUrl = loggerUrl; if (typeof Meteor === "undefined" || !Meteor.isClient) { throw new Error("MeteorClientHttpSender is only meant for Meteor client side."); } if (typeof HTTP === "undefined") { throw new Error("MeteorClientHttpSender needs the Meteor http package to be active."); } - _this.http = HTTP; - _this.requestHeaders = { + this.http = HTTP; + this.requestHeaders = { "Content-Type": "application/json", }; - return _this; } /** @inheritDoc */ - class_1.prototype.send = function (level, message, context) { + MeteorClientHttpSender.prototype.send = function (level, message, context) { var data = { level: level, message: message, context: {} }; if (typeof context !== "undefined") { data.context = context; @@ -63,7 +44,7 @@ var MeteorClientHttpSender = /** @class */ (function (_super) { }; this.http.post(this.loggerUrl, options, NullFn_1.default); }; - return class_1; -}(SenderBase_1.SenderBase)); -exports.default = MeteorClientHttpSender; + return MeteorClientHttpSender; +}()); +exports.MeteorClientHttpSender = MeteorClientHttpSender; //# sourceMappingURL=MeteorClientHttpSender.js.map \ No newline at end of file diff --git a/lib/Senders/MeteorClientHttpSender.js.map b/lib/Senders/MeteorClientHttpSender.js.map index a6adc34..2461010 100644 --- a/lib/Senders/MeteorClientHttpSender.js.map +++ b/lib/Senders/MeteorClientHttpSender.js.map @@ -1 +1 @@ -{"version":3,"file":"MeteorClientHttpSender.js","sourceRoot":"","sources":["../../src/Senders/MeteorClientHttpSender.ts"],"names":[],"mappings":";AAAA,2BAA2B;;;;;;;;;;;;;;;;;;AAE3B;;GAEG;AAEH,qDAA+B;AAC/B,2CAA0C;AAE1C;;;;GAIG;AACH,IAAM,sBAAsB;IAAiB,2BAAU;IAIrD,uCAAuC;IACvC;;;;;OAKG;IACH,iBAAmB,SAAiB;QAApC,YACE,iBAAO,SAYR;QAbkB,eAAS,GAAT,SAAS,CAAQ;QAElC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;SACjF;QACD,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;SACvF;QAED,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,KAAI,CAAC,cAAc,GAAG;YACpB,cAAc,EAAE,kBAAkB;SACnC,CAAC;;IACJ,CAAC;IAED,kBAAkB;IACX,sBAAI,GAAX,UAAY,KAAa,EAAE,OAAe,EAAE,OAAe;QACzD,IAAM,IAAI,GAAG,EAAE,KAAK,OAAA,EAAE,OAAO,SAAA,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAC7C,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;YAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACxB;QAED,IAAM,OAAO,GAAG;YACd,IAAI,MAAA;YACJ,OAAO,EAAE,IAAI,CAAC,cAAc;SAC7B,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,gBAAM,CAAC,CAAC;IAClD,CAAC;IACH,cAAC;AAAD,CAAC,AAvC8B,CAAc,uBAAU,EAuCtD,CAAC;AAEF,kBAAe,sBAAsB,CAAC"} \ No newline at end of file +{"version":3,"file":"MeteorClientHttpSender.js","sourceRoot":"","sources":["../../src/Senders/MeteorClientHttpSender.ts"],"names":[],"mappings":";AAAA,2BAA2B;;;;;AAE3B;;GAEG;AAEH,qDAA+B;AAG/B;;GAEG;AACH;IAIE,uCAAuC;IACvC;;;;;OAKG;IACH,gCAAmB,SAAiB;QAAjB,cAAS,GAAT,SAAS,CAAQ;QAClC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;SACjF;QACD,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;SACvF;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG;YACpB,cAAc,EAAE,kBAAkB;SACnC,CAAC;IACJ,CAAC;IAED,kBAAkB;IACX,qCAAI,GAAX,UAAY,KAAa,EAAE,OAAe,EAAE,OAAe;QACzD,IAAM,IAAI,GAAG,EAAE,KAAK,OAAA,EAAE,OAAO,SAAA,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAC7C,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;YAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACxB;QAED,IAAM,OAAO,GAAG;YACd,IAAI,MAAA;YACJ,OAAO,EAAE,IAAI,CAAC,cAAc;SAC7B,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,gBAAM,CAAC,CAAC;IAClD,CAAC;IACH,6BAAC;AAAD,CAAC,AAtCD,IAsCC;AAGC,wDAAsB"} \ No newline at end of file diff --git a/lib/Senders/MeteorClientMethodSender.d.ts b/lib/Senders/MeteorClientMethodSender.d.ts index ec8b3d6..82196a8 100644 --- a/lib/Senders/MeteorClientMethodSender.d.ts +++ b/lib/Senders/MeteorClientMethodSender.d.ts @@ -1,13 +1,11 @@ /** global: Meteor */ +import { ISender } from "./ISender"; /** * MeteorClientMethodSender send data from the client to the server over DDP. - * - * @extends SenderBase */ -declare const MeteorClientMethodSender: { - new (): { - /** @inheritDoc */ - send(level: number, message: string, context: object): void; - }; -}; -export default MeteorClientMethodSender; +declare class MeteorClientMethodSender implements ISender { + constructor(); + /** @inheritDoc */ + send(level: number, message: string, context: object): void; +} +export { MeteorClientMethodSender, }; diff --git a/lib/Senders/MeteorClientMethodSender.js b/lib/Senders/MeteorClientMethodSender.js index 06f3db5..9bb85df 100644 --- a/lib/Senders/MeteorClientMethodSender.js +++ b/lib/Senders/MeteorClientMethodSender.js @@ -1,53 +1,28 @@ "use strict"; /** global: Meteor */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); /** * @fileOverview Meteor Client Method Sender class. */ var Logger_1 = require("../Loggers/Logger"); -var SenderBase_1 = require("./SenderBase"); /** * MeteorClientMethodSender send data from the client to the server over DDP. - * - * @extends SenderBase */ -var MeteorClientMethodSender = /** @class */ (function (_super) { - __extends(class_1, _super); - /** - * @constructor - * - * @param {String} loggerUrl - * The absolute URL of the logger server. Usually /logger on the Meteor app. - */ - function class_1() { - var _this = _super.call(this) || this; +var MeteorClientMethodSender = /** @class */ (function () { + function MeteorClientMethodSender() { if (typeof Meteor === "undefined" || !Meteor.isClient) { throw new Error("MeteorClientMethodSender is only meant for Meteor client side."); } - return _this; } /** @inheritDoc */ - class_1.prototype.send = function (level, message, context) { + MeteorClientMethodSender.prototype.send = function (level, message, context) { var data = { level: level, message: message, context: {} }; if (typeof context !== "undefined") { data.context = context; } Meteor.call(Logger_1.Logger.METHOD, data); }; - return class_1; -}(SenderBase_1.SenderBase)); -exports.default = MeteorClientMethodSender; + return MeteorClientMethodSender; +}()); +exports.MeteorClientMethodSender = MeteorClientMethodSender; //# sourceMappingURL=MeteorClientMethodSender.js.map \ No newline at end of file diff --git a/lib/Senders/MeteorClientMethodSender.js.map b/lib/Senders/MeteorClientMethodSender.js.map index b5914d5..e390f1d 100644 --- a/lib/Senders/MeteorClientMethodSender.js.map +++ b/lib/Senders/MeteorClientMethodSender.js.map @@ -1 +1 @@ -{"version":3,"file":"MeteorClientMethodSender.js","sourceRoot":"","sources":["../../src/Senders/MeteorClientMethodSender.ts"],"names":[],"mappings":";AAAA,qBAAqB;;;;;;;;;;;;;;;AAErB;;GAEG;AAEH,4CAA2C;AAC3C,2CAA0C;AAE1C;;;;GAIG;AACH,IAAM,wBAAwB;IAAiB,2BAAU;IACvD;;;;;OAKG;IACH;QAAA,YACE,iBAAO,SAIR;QAHC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;SACnF;;IACH,CAAC;IAED,kBAAkB;IACX,sBAAI,GAAX,UAAY,KAAa,EAAE,OAAe,EAAE,OAAe;QACzD,IAAM,IAAI,GAAG,EAAE,KAAK,OAAA,EAAE,OAAO,SAAA,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAC7C,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;YAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACxB;QAED,MAAM,CAAC,IAAI,CAAC,eAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IACH,cAAC;AAAD,CAAC,AAvBgC,CAAc,uBAAU,EAuBxD,CAAC;AAEF,kBAAe,wBAAwB,CAAC"} \ No newline at end of file +{"version":3,"file":"MeteorClientMethodSender.js","sourceRoot":"","sources":["../../src/Senders/MeteorClientMethodSender.ts"],"names":[],"mappings":";AAAA,qBAAqB;;AAErB;;GAEG;AAEH,4CAA2C;AAG3C;;GAEG;AACH;IAEE;QACE,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrD,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;SACnF;IACH,CAAC;IAED,kBAAkB;IACX,uCAAI,GAAX,UAAY,KAAa,EAAE,OAAe,EAAE,OAAe;QACzD,IAAM,IAAI,GAAG,EAAE,KAAK,OAAA,EAAE,OAAO,SAAA,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAC7C,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;YAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACxB;QAED,MAAM,CAAC,IAAI,CAAC,eAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IACH,+BAAC;AAAD,CAAC,AAjBD,IAiBC;AAGC,4DAAwB"} \ No newline at end of file diff --git a/lib/Senders/MongodbSender.d.ts b/lib/Senders/MongodbSender.d.ts index 5e2c1ed..011e641 100644 --- a/lib/Senders/MongodbSender.d.ts +++ b/lib/Senders/MongodbSender.d.ts @@ -2,16 +2,24 @@ * @fileOverview MongoDB Sender class. */ import { Mongo } from "meteor/mongo"; +import { IContext } from "../IContext"; +import * as LogLevel from "../LogLevel"; +import { ISender } from "./ISender"; /** * MongodbSender sends logs to the Meteor standard database. - * - * @extends SenderBase */ -declare const MongodbSender: { - new (mongo: any, collection?: string | Mongo.Collection): { - store: Mongo.Collection; - /** @inheritDoc */ - send(level: number, message: string, context: object): void; - }; -}; -export default MongodbSender; +declare class MongodbSender implements ISender { + store: Mongo.Collection; + /** + * @constructor + * + * @param mongo + * The Meteor Mongo service. + * @param collection + * The collection or the name of the collection in which to log. + */ + constructor(mongo: any, collection?: string | Mongo.Collection); + /** @inheritDoc */ + send(level: LogLevel.Levels, message: string, context: IContext): void; +} +export { MongodbSender, }; diff --git a/lib/Senders/MongodbSender.js b/lib/Senders/MongodbSender.js index ebb3414..d457efb 100644 --- a/lib/Senders/MongodbSender.js +++ b/lib/Senders/MongodbSender.js @@ -1,17 +1,4 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { @@ -27,45 +14,38 @@ Object.defineProperty(exports, "__esModule", { value: true }); var IContext_1 = require("../IContext"); var Logger_1 = require("../Loggers/Logger"); var ServerLogger_1 = require("../Loggers/ServerLogger"); -var SenderBase_1 = require("./SenderBase"); /** * MongodbSender sends logs to the Meteor standard database. - * - * @extends SenderBase */ -var MongodbSender = /** @class */ (function (_super) { - __extends(class_1, _super); +var MongodbSender = /** @class */ (function () { // noinspection JSClassNamingConvention /** * @constructor * - * @param {Mongo} mongo + * @param mongo * The Meteor Mongo service. - * @param {(String|Collection)} collection + * @param collection * The collection or the name of the collection in which to log. */ - function class_1(mongo, collection) { + function MongodbSender(mongo, collection) { if (collection === void 0) { collection = "logger"; } - var _this = _super.call(this) || this; if (collection instanceof mongo.Collection) { - _this.store = collection; + this.store = collection; } else if (typeof collection === "string") { - var collectionName = collection; - _this.store = new mongo.Collection(collectionName); + this.store = new mongo.Collection(collection); } else { throw new Error("MongodbSender requires a Collection or a collection name"); } - return _this; } /** @inheritDoc */ - class_1.prototype.send = function (level, message, context) { + MongodbSender.prototype.send = function (level, message, context) { var defaultedContext = __assign({}, context, { timestamp: {} }); var doc = { level: level, message: message, context: {} }; // It should contain a timestamp.{side} object if it comes from any Logger. - if (typeof defaultedContext[IContext_1.TS_KEY] === "undefined") { - defaultedContext[IContext_1.TS_KEY] = { + if (typeof defaultedContext[IContext_1.KEY_TS] === "undefined") { + defaultedContext[IContext_1.KEY_TS] = { server: {}, }; } @@ -74,7 +54,7 @@ var MongodbSender = /** @class */ (function (_super) { Logger_1.Logger.stamp(doc.context, "send", ServerLogger_1.ServerSide); this.store.insert(doc); }; - return class_1; -}(SenderBase_1.SenderBase)); -exports.default = MongodbSender; + return MongodbSender; +}()); +exports.MongodbSender = MongodbSender; //# sourceMappingURL=MongodbSender.js.map \ No newline at end of file diff --git a/lib/Senders/MongodbSender.js.map b/lib/Senders/MongodbSender.js.map index e4d0321..d4a4a43 100644 --- a/lib/Senders/MongodbSender.js.map +++ b/lib/Senders/MongodbSender.js.map @@ -1 +1 @@ -{"version":3,"file":"MongodbSender.js","sourceRoot":"","sources":["../../src/Senders/MongodbSender.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wCAA6C;AAC7C,4CAA2C;AAC3C,wDAAqD;AACrD,2CAA0C;AAE1C;;;;GAIG;AACH,IAAM,aAAa;IAAiB,2BAAU;IAG5C,uCAAuC;IACvC;;;;;;;OAOG;IACH,iBAAY,KAAU,EAAE,UAAsD;QAAtD,2BAAA,EAAA,qBAAsD;QAA9E,YACE,iBAAO,SASR;QARC,IAAI,UAAU,YAAY,KAAK,CAAC,UAAU,EAAE;YAC1C,KAAI,CAAC,KAAK,GAAG,UAAsC,CAAC;SACrD;aAAM,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YACzC,IAAM,cAAc,GAAG,UAAU,CAAC;YAClC,KAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;SACnD;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;SAC7E;;IACH,CAAC;IAED,kBAAkB;IACX,sBAAI,GAAX,UAAY,KAAa,EAAE,OAAe,EAAE,OAAe;QACzD,IAAM,gBAAgB,gBAAkB,OAAO,IAAE,SAAS,EAAE,EAAE,GAAE,CAAC;QACjE,IAAM,GAAG,GAAG,EAAE,KAAK,OAAA,EAAE,OAAO,SAAA,EAAE,OAAO,EAAE,EAAc,EAAE,CAAC;QAExD,2EAA2E;QAC3E,IAAI,OAAO,gBAAgB,CAAC,iBAAM,CAAC,KAAK,WAAW,EAAE;YACnD,gBAAgB,CAAC,iBAAM,CAAC,GAAG;gBACzB,MAAM,EAAE,EAAE;aACX,CAAC;SACH;QACD,GAAG,CAAC,OAAO,GAAG,gBAAgB,CAAC;QAE/B,6DAA6D;QAC7D,eAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,yBAAU,CAAC,CAAC;QAC9C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACH,cAAC;AAAD,CAAC,AAzCqB,CAAc,uBAAU,EAyC7C,CAAC;AAEF,kBAAe,aAAa,CAAC"} \ No newline at end of file +{"version":3,"file":"MongodbSender.js","sourceRoot":"","sources":["../../src/Senders/MongodbSender.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAIA,wCAA0D;AAC1D,4CAAyC;AACzC,wDAAmD;AAInD;;GAEG;AACH;IAGE,uCAAuC;IACvC;;;;;;;OAOG;IACH,uBAAY,KAAU,EAAE,UAAsD;QAAtD,2BAAA,EAAA,qBAAsD;QAC5E,IAAI,UAAU,YAAY,KAAK,CAAC,UAAU,EAAE;YAC1C,IAAI,CAAC,KAAK,GAAG,UAAsC,CAAC;SACrD;aAAM,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YACzC,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;SAC/C;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;SAC7E;IACH,CAAC;IAED,kBAAkB;IACX,4BAAI,GAAX,UAAY,KAAsB,EAAE,OAAe,EAAE,OAAiB;QACpE,IAAM,gBAAgB,gBAAkB,OAAO,IAAE,SAAS,EAAE,EAAE,GAAE,CAAC;QACjE,IAAM,GAAG,GAAG,EAAE,KAAK,OAAA,EAAE,OAAO,SAAA,EAAE,OAAO,EAAE,EAAc,EAAE,CAAC;QAExD,2EAA2E;QAC3E,IAAI,OAAO,gBAAgB,CAAC,iBAAM,CAAC,KAAK,WAAW,EAAE;YACnD,gBAAgB,CAAC,iBAAM,CAAC,GAAG;gBACzB,MAAM,EAAE,EAAE;aACX,CAAC;SACH;QACD,GAAG,CAAC,OAAO,GAAG,gBAAgB,CAAC;QAE/B,6DAA6D;QAC7D,eAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,yBAA+B,CAAC,CAAC;QACnE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACH,oBAAC;AAAD,CAAC,AAvCD,IAuCC;AAGC,sCAAa"} \ No newline at end of file diff --git a/lib/Senders/NullSender.d.ts b/lib/Senders/NullSender.d.ts index 519304d..0b57f86 100644 --- a/lib/Senders/NullSender.d.ts +++ b/lib/Senders/NullSender.d.ts @@ -1,17 +1,14 @@ /** * @fileOverview NulllSender class. */ +import { ISender } from "./ISender"; +import { IContext } from "../IContext"; +import * as LogLevel from "../LogLevel"; /** * NullSender defines an explicit null sender. - * - * Although SenderBase is also null, this is not its defining characteristic - * hence this alias. - * - * @extends SenderBase */ -declare const NullSender: { - new (): { - send(_1: Levels, _2: string, _3: object): void; - }; -}; -export default NullSender; +declare class NullSender implements ISender { + /** @inheritDoc */ + send(_1: LogLevel.Levels, _2: string, _3: IContext): void; +} +export { NullSender, }; diff --git a/lib/Senders/NullSender.js b/lib/Senders/NullSender.js index 7fa0596..479d73b 100644 --- a/lib/Senders/NullSender.js +++ b/lib/Senders/NullSender.js @@ -2,35 +2,19 @@ /** * @fileOverview NulllSender class. */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); -var SenderBase_1 = require("./SenderBase"); /** * NullSender defines an explicit null sender. - * - * Although SenderBase is also null, this is not its defining characteristic - * hence this alias. - * - * @extends SenderBase */ -var NullSender = /** @class */ (function (_super) { - __extends(class_1, _super); - function class_1() { - return _super !== null && _super.apply(this, arguments) || this; +var NullSender = /** @class */ (function () { + function NullSender() { } - return class_1; -}(SenderBase_1.SenderBase)); -exports.default = NullSender; + /** @inheritDoc */ + NullSender.prototype.send = function (_1, _2, _3) { + // Explicit return is needed to avoid the TSlint no-empty warning. + return; + }; + return NullSender; +}()); +exports.NullSender = NullSender; //# sourceMappingURL=NullSender.js.map \ No newline at end of file diff --git a/lib/Senders/NullSender.js.map b/lib/Senders/NullSender.js.map index c607034..486f3a6 100644 --- a/lib/Senders/NullSender.js.map +++ b/lib/Senders/NullSender.js.map @@ -1 +1 @@ -{"version":3,"file":"NullSender.js","sourceRoot":"","sources":["../../src/Senders/NullSender.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;AAEH,2CAA0C;AAE1C;;;;;;;GAOG;AACH,IAAM,UAAU;IAAiB,2BAAU;IAAxB;;IAA0B,CAAC;IAAD,cAAC;AAAD,CAAC,AAA3B,CAAc,uBAAU,EAAG,CAAC;AAE/C,kBAAe,UAAU,CAAC"} \ No newline at end of file +{"version":3,"file":"NullSender.js","sourceRoot":"","sources":["../../src/Senders/NullSender.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAMH;;GAEG;AACH;IAAA;IAMA,CAAC;IALC,kBAAkB;IACX,yBAAI,GAAX,UAAY,EAAmB,EAAE,EAAU,EAAE,EAAY;QACvD,kEAAkE;QAClE,OAAO;IACT,CAAC;IACH,iBAAC;AAAD,CAAC,AAND,IAMC;AAGC,gCAAU"} \ No newline at end of file diff --git a/lib/Senders/SenderBase.d.ts b/lib/Senders/SenderBase.d.ts index 7007d18..df96677 100644 --- a/lib/Senders/SenderBase.d.ts +++ b/lib/Senders/SenderBase.d.ts @@ -1,6 +1,8 @@ /** - * @fileOverview Base Sender class. + * @fileOverview + * Base Sender class. */ +import { IContext } from "../IContext"; import * as LogLevel from "../LogLevel"; import { ISender } from "./ISender"; /** @@ -8,6 +10,6 @@ import { ISender } from "./ISender"; */ declare class SenderBase implements ISender { /** @inheritDoc */ - send(_1: LogLevel.Levels, _2: string, _3: object): void; + send(_1: LogLevel.Levels, _2: string, _3: IContext): void; } export { SenderBase, }; diff --git a/lib/Senders/SenderBase.js b/lib/Senders/SenderBase.js index 6491f4b..76ba0de 100644 --- a/lib/Senders/SenderBase.js +++ b/lib/Senders/SenderBase.js @@ -1,6 +1,7 @@ "use strict"; /** - * @fileOverview Base Sender class. + * @fileOverview + * Base Sender class. */ Object.defineProperty(exports, "__esModule", { value: true }); /** diff --git a/lib/Senders/SenderBase.js.map b/lib/Senders/SenderBase.js.map index cab644f..01cd1eb 100644 --- a/lib/Senders/SenderBase.js.map +++ b/lib/Senders/SenderBase.js.map @@ -1 +1 @@ -{"version":3,"file":"SenderBase.js","sourceRoot":"","sources":["../../src/Senders/SenderBase.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAKH;;GAEG;AACH;IAAA;IAGA,CAAC;IAFC,kBAAkB;IACX,yBAAI,GAAX,UAAY,EAAmB,EAAE,EAAU,EAAE,EAAU,IAAU,OAAO,CAAC,CAAC;IAC5E,iBAAC;AAAD,CAAC,AAHD,IAGC;AAGC,gCAAU"} \ No newline at end of file +{"version":3,"file":"SenderBase.js","sourceRoot":"","sources":["../../src/Senders/SenderBase.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAMH;;GAEG;AACH;IAAA;IAGA,CAAC;IAFC,kBAAkB;IACX,yBAAI,GAAX,UAAY,EAAmB,EAAE,EAAU,EAAE,EAAY,IAAU,OAAO,CAAC,CAAC;IAC9E,iBAAC;AAAD,CAAC,AAHD,IAGC;AAGC,gCAAU"} \ No newline at end of file diff --git a/lib/Senders/SyslogSender.d.ts b/lib/Senders/SyslogSender.d.ts index f4f4ecb..5eeb86d 100644 --- a/lib/Senders/SyslogSender.d.ts +++ b/lib/Senders/SyslogSender.d.ts @@ -4,6 +4,7 @@ import modernSyslog = require("modern-syslog"); import { IContext } from "../IContext"; import * as LogLevel from "../LogLevel"; +import { ISender } from "./ISender"; declare type Serializer = (doc: object) => string; interface ISyslogContext { message: string; @@ -21,45 +22,64 @@ interface ISyslogContext { * @see https://tools.ietf.org/html/rfc3164#section-4.1 * @see https://tools.ietf.org/html/rfc5424#section-6.1 * @see https://tools.ietf.org/html/rfc6587#section-3.4.1 - * - * @extends SenderBase */ -declare const SyslogSender: { - new (ident: null | undefined, syslogOptions: number | undefined, syslogFacility: number | null | undefined, syslog: any, formatOptions?: null, serialize?: null): { - facility: number; - formatOptions: object; - ident: string; - option: number; - serialize: Serializer; - syslog: any; - /** - * @inheritDoc - */ - send(level: number, message: string, context: IContext): void; - /** - * Serialize a message to JSON. Handles circular documents with a fallback. - * - * @param doc - * - an object with 3 mandatory keys and an optional one: - * - message: a string or object, as per Meteor Log package - * - level: a numeric severity level, like modernSyslog.level.LOG_DEBUG - * - facility: a syslog facility, like modernSyslog.facility.LOG_LOCAL0 - * - (Optional) context: an object of context values. Anything goes. - * - * @returns - * The serialized version of the doc argument under the formatOptions rules. - */ - serializeDefault(doc: ISyslogContext): string; - /** - * Serialize a message to Node.js util.inspect format. - * - * @param doc - * A document to serialize. Any structure. - * - * @returns - * The serialized version of the doc argument under the formatOptions rules. - */ - serializeInspect(doc: object): string; - }; -}; -export default SyslogSender; +declare class SyslogSender implements ISender { + syslog: any; + facility: number; + formatOptions: object; + ident: string; + option: number; + serialize: Serializer; + /** + * @constructor + * + * @param ident + * Optional: the syslog identifier. Used as a prefix on messages. + * @param syslogOptions + * Optional: a bit-level OR of syslog.LOG* option constants. + * @param syslogFacility + * Optional: one of the standard RFC5424 facilities. + * @param syslog + * The modern-syslog service or a compatible alternative. + * @param formatOptions + * Optional : The options used to format the message. The contents depends + * on the serializer used. Defaults to { depth: 5 }), for the legacy + * "util.inspect" serializer, now available as serializeInspect(). + * @param serialize + * Optional: a serializer function converting a document to a string. + * + * @see serializeDefault + * @see modern-syslog/core.cc + */ + constructor(ident: null | undefined, syslogOptions: number | undefined, syslogFacility: number | null | undefined, syslog: any, // modernSyslog, + formatOptions?: null, serialize?: null); + /** + * @inheritDoc + */ + send(level: number, message: string, context: IContext): void; + /** + * Serialize a message to JSON. Handles circular documents with a fallback. + * + * @param doc + * - an object with 3 mandatory keys and an optional one: + * - message: a string or object, as per Meteor Log package + * - level: a numeric severity level, like modernSyslog.level.LOG_DEBUG + * - facility: a syslog facility, like modernSyslog.facility.LOG_LOCAL0 + * - (Optional) context: an object of context values. Anything goes. + * + * @returns + * The serialized version of the doc argument under the formatOptions rules. + */ + serializeDefault(doc: ISyslogContext): string; + /** + * Serialize a message to Node.js util.inspect format. + * + * @param doc + * A document to serialize. Any structure. + * + * @returns + * The serialized version of the doc argument under the formatOptions rules. + */ + serializeInspect(doc: object): string; +} +export { SyslogSender, }; diff --git a/lib/Senders/SyslogSender.js b/lib/Senders/SyslogSender.js index 796b22f..d8558c0 100644 --- a/lib/Senders/SyslogSender.js +++ b/lib/Senders/SyslogSender.js @@ -2,19 +2,6 @@ /** * @fileOverview Syslog Sender class. */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; @@ -29,7 +16,6 @@ var util = __importStar(require("util")); var IContext_1 = require("../IContext"); var Logger_1 = require("../Loggers/Logger"); var ServerLogger_1 = require("../Loggers/ServerLogger"); -var SenderBase_1 = require("./SenderBase"); /** * SyslogSender sends messages to a syslog server. * @@ -40,11 +26,8 @@ var SenderBase_1 = require("./SenderBase"); * @see https://tools.ietf.org/html/rfc3164#section-4.1 * @see https://tools.ietf.org/html/rfc5424#section-6.1 * @see https://tools.ietf.org/html/rfc6587#section-3.4.1 - * - * @extends SenderBase */ -var SyslogSender = /** @class */ (function (_super) { - __extends(class_1, _super); +var SyslogSender = /** @class */ (function () { // noinspection JSClassNamingConvention /** * @constructor @@ -67,30 +50,28 @@ var SyslogSender = /** @class */ (function (_super) { * @see serializeDefault * @see modern-syslog/core.cc */ - function class_1(ident, syslogOptions, syslogFacility, syslog, //modernSyslog, + function SyslogSender(ident, syslogOptions, syslogFacility, syslog, // modernSyslog, formatOptions, serialize) { if (ident === void 0) { ident = null; } if (syslogOptions === void 0) { syslogOptions = 0; } if (syslogFacility === void 0) { syslogFacility = null; } if (formatOptions === void 0) { formatOptions = null; } if (serialize === void 0) { serialize = null; } - var _this = _super.call(this) || this; - _this.syslog = syslog; + this.syslog = syslog; var programName = path.basename(process.argv[1]); var actualIdent = ident || programName; - _this.syslog = syslog || modernSyslog; - _this.facility = syslogFacility || _this.syslog.facility.LOG_LOCAL0; - _this.ident = actualIdent; - _this.option = syslogOptions || (_this.syslog.option.LOG_PID); - _this.formatOptions = formatOptions || { depth: 5 }; - _this.serialize = serialize || _this.serializeDefault.bind(_this); - _this.syslog.open(_this.ident, _this.option, _this.facility); - return _this; + this.syslog = syslog || modernSyslog; + this.facility = syslogFacility || this.syslog.facility.LOG_LOCAL0; + this.ident = actualIdent; + this.option = syslogOptions || (this.syslog.option.LOG_PID); + this.formatOptions = formatOptions || { depth: 5 }; + this.serialize = serialize || this.serializeDefault.bind(this); + this.syslog.open(this.ident, this.option, this.facility); } /** * @inheritDoc */ - class_1.prototype.send = function (level, message, context) { + SyslogSender.prototype.send = function (level, message, context) { var _a; var doc = { facility: this.syslog.facility[this.facility], @@ -102,10 +83,10 @@ var SyslogSender = /** @class */ (function (_super) { } // It should contain a timestamp.{side} object if it comes from any Logger. if (typeof doc.context === "undefined") { - doc.context = (_a = {}, _a[IContext_1.TS_KEY] = { server: {} }, _a); + doc.context = (_a = {}, _a[IContext_1.KEY_TS] = { server: {} }, _a); } - else if (typeof doc.context[IContext_1.TS_KEY] === "undefined") { - doc.context[IContext_1.TS_KEY] = {}; + else if (typeof doc.context[IContext_1.KEY_TS] === "undefined") { + doc.context[IContext_1.KEY_TS] = {}; } // doc.context.timestamp.server is known to exist from above. Logger_1.Logger.stamp(doc.context, "send", ServerLogger_1.ServerLogger.side); @@ -124,7 +105,7 @@ var SyslogSender = /** @class */ (function (_super) { * @returns * The serialized version of the doc argument under the formatOptions rules. */ - class_1.prototype.serializeDefault = function (doc) { + SyslogSender.prototype.serializeDefault = function (doc) { var result; try { result = JSON.stringify(doc); @@ -136,9 +117,8 @@ var SyslogSender = /** @class */ (function (_super) { logger_error: "Cannot JSON.stringify logged data: " + e1.message + ".", raw: util.inspect(doc, this.formatOptions), }; - if (typeof doc.message === "string") { - step1.message = doc.message; - } + // Since doc is a SyslogContext, doc.message is a string, no need to test. + step1.message = doc.message; try { result = JSON.stringify(step1); } @@ -160,11 +140,10 @@ var SyslogSender = /** @class */ (function (_super) { * @returns * The serialized version of the doc argument under the formatOptions rules. */ - class_1.prototype.serializeInspect = function (doc) { - var result = util.inspect(doc, this.formatOptions); - return result; + SyslogSender.prototype.serializeInspect = function (doc) { + return util.inspect(doc, this.formatOptions); }; - return class_1; -}(SenderBase_1.SenderBase)); -exports.default = SyslogSender; + return SyslogSender; +}()); +exports.SyslogSender = SyslogSender; //# sourceMappingURL=SyslogSender.js.map \ No newline at end of file diff --git a/lib/Senders/SyslogSender.js.map b/lib/Senders/SyslogSender.js.map index 8609f13..1ed89ea 100644 --- a/lib/Senders/SyslogSender.js.map +++ b/lib/Senders/SyslogSender.js.map @@ -1 +1 @@ -{"version":3,"file":"SyslogSender.js","sourceRoot":"","sources":["../../src/Senders/SyslogSender.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAA+C;AA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AG,CAAC,KAAK;gBAChB,YAAY,EAAE,wCAAsC,EAAE,CAAC,OAAO,MAAG;gBACjE,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC;aAC3C,CAAC;YAEF,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE;gBACnC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;aAC7B;YAED,IAAI;gBACF,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;aAChC;YAAC,OAAO,EAAE,EAAE;gBACX,yCAAyC;gBACzC,uDAAuD;gBACvD,kCAAkC;gBAClC,MAAM,GAAG,sEAAsE,CAAC;aACjF;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;;OAQG;IACI,kCAAgB,GAAvB,UAAwB,GAAW;QACjC,IAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,cAAC;AAAD,CAAC,AA5IoB,CAAc,uBAAU,EA4I5C,CAAC;AAEF,kBAAe,YAAY,CAAC"} \ No newline at end of file +{"version":3,"file":"SyslogSender.js","sourceRoot":"","sources":["../../src/Senders/SyslogSender.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;AAEH,4CAA+C;AAC/C,yCAA6B;AAC7B,yCAA6B;AAC7B,wCAA6C;AAC7C,4CAAyC;AACzC,wDAAqD;AAarD;;;;;;;;;;GAUG;AACH;IAOE,uCAAuC;IACvC;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,sBACE,KAAY,EACZ,aAAyB,EACzB,cAAoC,EAC7B,MAAW,EAAE,gBAAgB;IACpC,aAAoB,EACpB,SAAgB;QALhB,sBAAA,EAAA,YAAY;QACZ,8BAAA,EAAA,iBAAyB;QACzB,+BAAA,EAAA,qBAAoC;QAEpC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C;aACjF;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;;OAQG;IACI,uCAAgB,GAAvB,UAAwB,GAAW;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC/C,CAAC;IACH,mBAAC;AAAD,CAAC,AAzID,IAyIC;AAGC,oCAAY"} \ No newline at end of file diff --git a/lib/Senders/TeeSender.d.ts b/lib/Senders/TeeSender.d.ts index 210bf9e..2cb0e28 100644 --- a/lib/Senders/TeeSender.d.ts +++ b/lib/Senders/TeeSender.d.ts @@ -1,17 +1,22 @@ /** * @fileOverview Tee Sender class. */ +import { IContext } from "../IContext"; +import * as LogLevel from "../LogLevel"; import { ISender } from "./ISender"; /** * Like a UNIX tee(1), the TeeSender sends its input to multiple outputs. - * - * @extends SenderBase */ -declare const TeeSender: { - new (senders: ISender[]): { - senders: ISender[]; - /** @inheritdoc */ - send(level: number, message: string, context: object): void; - }; -}; -export default TeeSender; +declare class TeeSender implements ISender { + senders: ISender[]; + /** + * Constructor. + * + * @param {Array} senders + * An array of senders to which to send the input. + */ + constructor(senders: ISender[]); + /** @inheritdoc */ + send(level: LogLevel.Levels, message: string, context: IContext): void; +} +export { TeeSender, }; diff --git a/lib/Senders/TeeSender.js b/lib/Senders/TeeSender.js index cba9401..cb41044 100644 --- a/lib/Senders/TeeSender.js +++ b/lib/Senders/TeeSender.js @@ -2,44 +2,25 @@ /** * @fileOverview Tee Sender class. */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); -var SenderBase_1 = require("./SenderBase"); /** * Like a UNIX tee(1), the TeeSender sends its input to multiple outputs. - * - * @extends SenderBase */ -var TeeSender = /** @class */ (function (_super) { - __extends(class_1, _super); +var TeeSender = /** @class */ (function () { /** * Constructor. * * @param {Array} senders * An array of senders to which to send the input. */ - function class_1(senders) { - var _this = _super.call(this) || this; - _this.senders = senders; - return _this; + function TeeSender(senders) { + this.senders = senders; } /** @inheritdoc */ - class_1.prototype.send = function (level, message, context) { + TeeSender.prototype.send = function (level, message, context) { this.senders.map(function (sender) { return sender.send(level, message, context); }); }; - return class_1; -}(SenderBase_1.SenderBase)); -exports.default = TeeSender; + return TeeSender; +}()); +exports.TeeSender = TeeSender; //# sourceMappingURL=TeeSender.js.map \ No newline at end of file diff --git a/lib/Senders/TeeSender.js.map b/lib/Senders/TeeSender.js.map index 488f398..a37d6a1 100644 --- a/lib/Senders/TeeSender.js.map +++ b/lib/Senders/TeeSender.js.map @@ -1 +1 @@ -{"version":3,"file":"TeeSender.js","sourceRoot":"","sources":["../../src/Senders/TeeSender.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;AAGH,2CAA0C;AAE1C;;;;GAIG;AACH,IAAM,SAAS;IAAiB,2BAAU;IACxC;;;;;OAKG;IACH,iBAAmB,OAAkB;QAArC,YACE,iBAAO,SACR;QAFkB,aAAO,GAAP,OAAO,CAAW;;IAErC,CAAC;IAED,kBAAkB;IACX,sBAAI,GAAX,UAAY,KAAa,EAAE,OAAe,EAAE,OAAe;QACzD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAApC,CAAoC,CAAC,CAAC;IACrE,CAAC;IACH,cAAC;AAAD,CAAC,AAfiB,CAAc,uBAAU,EAezC,CAAC;AAEF,kBAAe,SAAS,CAAC"} \ No newline at end of file +{"version":3,"file":"TeeSender.js","sourceRoot":"","sources":["../../src/Senders/TeeSender.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAMH;;GAEG;AACH;IACE;;;;;OAKG;IACH,mBAAmB,OAAkB;QAAlB,YAAO,GAAP,OAAO,CAAW;IAAG,CAAC;IAEzC,kBAAkB;IACX,wBAAI,GAAX,UAAY,KAAsB,EAAE,OAAe,EAAE,OAAiB;QACpE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAApC,CAAoC,CAAC,CAAC;IACrE,CAAC;IACH,gBAAC;AAAD,CAAC,AAbD,IAaC;AAGC,8BAAS"} \ No newline at end of file diff --git a/lib/Strategies/IStrategy.d.ts b/lib/Strategies/IStrategy.d.ts index 84f7083..84eb8a3 100644 --- a/lib/Strategies/IStrategy.d.ts +++ b/lib/Strategies/IStrategy.d.ts @@ -1,3 +1,4 @@ +import { IContext } from "../IContext"; import { ILogger } from "../Loggers/ILogger"; import * as LogLevel from "../LogLevel"; import { ISender } from "../Senders/ISender"; @@ -15,7 +16,7 @@ interface IStrategy { * @returns * An array of senders to use for this event. */ - selectSenders(level: LogLevel.Levels, message: string, context: object): ISender[]; + selectSenders(level: LogLevel.Levels, message: string, context: IContext): ISender[]; /** * This method may modify the logger methods, e.g. to do nothing on debug. * diff --git a/lib/Strategies/LeveledStrategy.d.ts b/lib/Strategies/LeveledStrategy.d.ts index 6706c4a..8db619e 100644 --- a/lib/Strategies/LeveledStrategy.d.ts +++ b/lib/Strategies/LeveledStrategy.d.ts @@ -1,24 +1,40 @@ /** * @fileOverview Level-based Strategy. */ +import { IContext } from "../IContext"; import { ILogger } from "../Loggers/ILogger"; import * as LogLevel from "../LogLevel"; import { ISender } from "../Senders/ISender"; +import { IStrategy } from "./IStrategy"; +import { StrategyBase } from "./StrategyBase"; /** * LeveledStrategy defines a single sender per level. * * @extends StrategyBase */ -declare const LeveledStrategy: { - new (low: ISender, medium: ISender, high: ISender, minLow?: LogLevel.Levels, maxHigh?: LogLevel.Levels): { - low: ISender; - medium: ISender; - high: ISender; - minLow: LogLevel.Levels; - maxHigh: LogLevel.Levels; - customizeLogger(logger: ILogger): void; - selectSenders(level: LogLevel.Levels, _2: string, _3: object): ISender[]; - senders: ISender[]; - }; -}; -export default LeveledStrategy; +declare class LeveledStrategy extends StrategyBase implements IStrategy { + low: ISender; + medium: ISender; + high: ISender; + minLow: LogLevel.Levels; + maxHigh: LogLevel.Levels; + /** + * @constructor + * + * @param {function} low + * The Sender to use for low-interest events. + * @param {function} medium + * The Sender to use for medium-interest events. + * @param {function} high + * The Sender to use for high-interest events. + * @param {int} minLow + * The minimum level to handle as a low-interest event. + * @param {int} maxHigh + * The maximum level to handle as a high-interest event. + */ + constructor(low: ISender, medium: ISender, high: ISender, minLow?: LogLevel.Levels, maxHigh?: LogLevel.Levels); + /** @inheritDoc */ + customizeLogger(logger: ILogger): void; + selectSenders(level: LogLevel.Levels, _2: string, _3: IContext): ISender[]; +} +export { LeveledStrategy, }; diff --git a/lib/Strategies/LeveledStrategy.js b/lib/Strategies/LeveledStrategy.js index f5e4cea..3a25532 100644 --- a/lib/Strategies/LeveledStrategy.js +++ b/lib/Strategies/LeveledStrategy.js @@ -28,16 +28,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); var LogLevel = __importStar(require("../LogLevel")); var NullFn_1 = __importDefault(require("../NullFn")); -var NullSender_1 = __importDefault(require("../Senders/NullSender")); -var SenderBase_1 = require("../Senders/SenderBase"); -var StrategyBase_1 = __importDefault(require("./StrategyBase")); +var NullSender_1 = require("../Senders/NullSender"); +var StrategyBase_1 = require("./StrategyBase"); /** * LeveledStrategy defines a single sender per level. * * @extends StrategyBase */ var LeveledStrategy = /** @class */ (function (_super) { - __extends(class_1, _super); + __extends(LeveledStrategy, _super); // noinspection JSClassNamingConvention /** * @constructor @@ -53,7 +52,7 @@ var LeveledStrategy = /** @class */ (function (_super) { * @param {int} maxHigh * The maximum level to handle as a high-interest event. */ - function class_1(low, medium, high, minLow, maxHigh) { + function LeveledStrategy(low, medium, high, minLow, maxHigh) { if (minLow === void 0) { minLow = LogLevel.DEBUG; } if (maxHigh === void 0) { maxHigh = LogLevel.WARNING; } var _this = @@ -66,21 +65,23 @@ var LeveledStrategy = /** @class */ (function (_super) { _this.maxHigh = maxHigh; _this.senders = [low, medium, high]; _this.senders.forEach(function (sender) { - if (!(sender instanceof SenderBase_1.SenderBase)) { - throw new Error("LeveledStrategy: senders must be instances of a Sender class."); + // Not really an "implements ISender" check, but cheaper and more useful. + if (!sender.send) { + throw new Error("LeveledStrategy: senders must implement the ISender \"send()\" method."); } }); return _this; } - class_1.prototype.customizeLogger = function (logger) { + /** @inheritDoc */ + LeveledStrategy.prototype.customizeLogger = function (logger) { var _this = this; ["low", "medium", "high"].forEach(function (level) { - if (_this[level] instanceof NullSender_1.default) { + if (_this[level] instanceof NullSender_1.NullSender) { logger.debug = NullFn_1.default; } }); }; - class_1.prototype.selectSenders = function (level, _2, _3) { + LeveledStrategy.prototype.selectSenders = function (level, _2, _3) { var sender; if (level >= this.minLow) { sender = this.low; @@ -93,7 +94,7 @@ var LeveledStrategy = /** @class */ (function (_super) { } return [sender]; }; - return class_1; -}(StrategyBase_1.default)); -exports.default = LeveledStrategy; + return LeveledStrategy; +}(StrategyBase_1.StrategyBase)); +exports.LeveledStrategy = LeveledStrategy; //# sourceMappingURL=LeveledStrategy.js.map \ No newline at end of file diff --git a/lib/Strategies/LeveledStrategy.js.map b/lib/Strategies/LeveledStrategy.js.map index 24c5230..a9acd20 100644 --- a/lib/Strategies/LeveledStrategy.js.map +++ b/lib/Strategies/LeveledStrategy.js.map @@ -1 +1 @@ -{"version":3,"file":"LeveledStrategy.js","sourceRoot":"","sources":["../../src/Strategies/LeveledStrategy.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,oDAAwC;AAC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SACnB;aAAM,IAAI,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE;YAChC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;SACpB;aAAM;YACL,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;SACtB;QAED,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IACH,cAAC;AAAD,CAAC,AAtDuB,CAAc,sBAAY,EAsDjD,CAAC;AAEF,kBAAe,eAAe,CAAC"} \ No newline at end of file +{"version":3,"file":"LeveledStrategy.js","sourceRoot":"","sources":["../../src/Strategies/LeveledStrategy.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;AAIH,oDAAwC;AACxC,qDAA+B;AAE/B,oDAAmD;AAEnD,+CAA8C;AAE9C;;;;GAIG;AACH;IAA8B,mCAAY;IAExC,uCAAuC;IACvC;;;;;;;;;;;;;OAaG;IACH,yBACS,GAAY,EACZ,MAAe,EACf,IAAa,EACb,MAAwC,EACxC,OAA2C;QAD3C,uBAAA,EAAA,SAA0B,QAAQ,CAAC,KAAK;QACxC,wBAAA,EAAA,UAA2B,QAAQ,CAAC,OAAO;QALpD;QAME,2CAA2C;QAC3C,kBAAM,KAAK,CAAC,SASb;QAfQ,SAAG,GAAH,GAAG,CAAS;QACZ,YAAM,GAAN,MAAM,CAAS;QACf,UAAI,GAAJ,IAAI,CAAS;QACb,YAAM,GAAN,MAAM,CAAkC;QACxC,aAAO,GAAP,OAAO,CAAoC;QAGlD,KAAI,CAAC,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAEnC,KAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;YAC1B,yEAAyE;YACzE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;gBAChB,MAAM,IAAI,KAAK,CAAC,wEAAsE,CAAC,CAAC;aACzF;QACH,CAAC,CAAC,CAAC;;IACL,CAAC;IAED,kBAAkB;IACX,yCAAe,GAAtB,UAAuB,MAAe;QAAtC,iBAMC;QALC,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,UAAC,KAAK;YACtC,IAAI,KAAI,CAAC,KAAmB,CAAC,YAAY,uBAAU,EAAE;gBACnD,MAAM,CAAC,KAAK,GAAG,gBAAM,CAAC;aACvB;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,uCAAa,GAApB,UAAqB,KAAsB,EAAE,EAAU,EAAE,EAAY;QACnE,IAAI,MAAM,CAAC;QACX,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;YACxB,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;SACnB;aAAM,IAAI,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE;YAChC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;SACpB;aAAM;YACL,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;SACtB;QAED,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IACH,sBAAC;AAAD,CAAC,AAxDD,CAA8B,2BAAY,GAwDzC;AAGC,0CAAe"} \ No newline at end of file diff --git a/lib/Strategies/StrategyBase.d.ts b/lib/Strategies/StrategyBase.d.ts index 51495fc..26b6275 100644 --- a/lib/Strategies/StrategyBase.d.ts +++ b/lib/Strategies/StrategyBase.d.ts @@ -4,18 +4,18 @@ import { ILogger } from "../Loggers/ILogger"; import * as LogLevel from "../LogLevel"; import { ISender } from "../Senders/ISender"; +import { IStrategy } from "./IStrategy"; /** * StrategyBase is an "abstract" strategy. * * Strategies customize the active Sender instances for a given log event. - * - * @see SenderBase */ -declare const StrategyBase: { - new (init?: boolean): { - senders: ISender[]; - selectSenders(_1: LogLevel.Levels, _2: string, _3: object): ISender[]; - customizeLogger(_: ILogger): void; - }; -}; -export default StrategyBase; +declare class StrategyBase implements IStrategy { + senders: ISender[]; + constructor(init?: boolean); + /** @inheritDoc */ + selectSenders(_1: LogLevel.Levels, _2: string, _3: object): ISender[]; + /** @inheritDoc */ + customizeLogger(_: ILogger): void; +} +export { StrategyBase, }; diff --git a/lib/Strategies/StrategyBase.js b/lib/Strategies/StrategyBase.js index 7c1e948..9783f5e 100644 --- a/lib/Strategies/StrategyBase.js +++ b/lib/Strategies/StrategyBase.js @@ -2,32 +2,29 @@ /** * @fileOverview Base Strategy. */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); -var NullSender_1 = __importDefault(require("../Senders/NullSender")); +var NullSender_1 = require("../Senders/NullSender"); /** * StrategyBase is an "abstract" strategy. * * Strategies customize the active Sender instances for a given log event. - * - * @see SenderBase */ var StrategyBase = /** @class */ (function () { - function class_1(init) { + function StrategyBase(init) { if (init === void 0) { init = true; } // @see https://github.com/Microsoft/TypeScript/issues/17293 this.senders = []; if (init) { - this.senders = [new NullSender_1.default()]; + this.senders = [new NullSender_1.NullSender()]; } } - class_1.prototype.selectSenders = function (_1, _2, _3) { + /** @inheritDoc */ + StrategyBase.prototype.selectSenders = function (_1, _2, _3) { return this.senders; }; - class_1.prototype.customizeLogger = function (_) { return; }; - return class_1; + /** @inheritDoc */ + StrategyBase.prototype.customizeLogger = function (_) { return; }; + return StrategyBase; }()); -exports.default = StrategyBase; +exports.StrategyBase = StrategyBase; //# sourceMappingURL=StrategyBase.js.map \ No newline at end of file diff --git a/lib/Strategies/StrategyBase.js.map b/lib/Strategies/StrategyBase.js.map index b672767..b1cf355 100644 --- a/lib/Strategies/StrategyBase.js.map +++ b/lib/Strategies/StrategyBase.js.map @@ -1 +1 @@ -{"version":3,"file":"StrategyBase.js","sourceRoot":"","sources":["../../src/Strategies/StrategyBase.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;AAKH,qEAA+C;AAG/C;;;;;;GAMG;AACH,IAAM,YAAY;IAKhB,iBAAY,IAAW;QAAX,qBAAA,EAAA,WAAW;QAHvB,4DAA4D;QACrD,YAAO,GAAc,EAAE,CAAC;QAG7B,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,oBAAU,EAAE,CAAC,CAAC;SACnC;IACH,CAAC;IAEM,+BAAa,GAApB,UAAqB,EAAmB,EAAE,EAAU,EAAE,EAAU;QAC9D,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,iCAAe,GAAtB,UAAuB,CAAU,IAAU,OAAO,CAAC,CAAC;IACtD,cAAC;AAAD,CAAC,AAhBoB,GAgBpB,CAAC;AAEF,kBAAe,YAAY,CAAC"} \ No newline at end of file +{"version":3,"file":"StrategyBase.js","sourceRoot":"","sources":["../../src/Strategies/StrategyBase.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAKH,oDAAmD;AAGnD;;;;GAIG;AACH;IAKE,sBAAY,IAAW;QAAX,qBAAA,EAAA,WAAW;QAHvB,4DAA4D;QACrD,YAAO,GAAc,EAAE,CAAC;QAG7B,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,uBAAU,EAAE,CAAC,CAAC;SACnC;IACH,CAAC;IAED,kBAAkB;IACX,oCAAa,GAApB,UAAqB,EAAmB,EAAE,EAAU,EAAE,EAAU;QAC9D,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,kBAAkB;IACX,sCAAe,GAAtB,UAAuB,CAAU,IAAU,OAAO,CAAC,CAAC;IACtD,mBAAC;AAAD,CAAC,AAlBD,IAkBC;AAGC,oCAAY"} \ No newline at end of file diff --git a/lib/Strategies/TrivialStrategy.d.ts b/lib/Strategies/TrivialStrategy.d.ts index 46446a2..9885162 100644 --- a/lib/Strategies/TrivialStrategy.d.ts +++ b/lib/Strategies/TrivialStrategy.d.ts @@ -2,6 +2,8 @@ * @fileOverview Trivial Strategy. */ import { ISender } from "../Senders/ISender"; +import { IStrategy } from "./IStrategy"; +import { StrategyBase } from "./StrategyBase"; /** * This strategy uses a single sender for all configurations. * @@ -9,11 +11,13 @@ import { ISender } from "../Senders/ISender"; * * @extends StrategyBase */ -declare const TrivialStrategy: { - new (sender: ISender): { - senders: ISender[]; - selectSenders(_1: Levels, _2: string, _3: object): ISender[]; - customizeLogger(_: import("../Loggers/ILogger").ILogger): void; - }; -}; -export default TrivialStrategy; +declare class TrivialStrategy extends StrategyBase implements IStrategy { + /** + * @constructor + * + * @param {function} sender + * The Sender to use for all events + */ + constructor(sender: ISender); +} +export { TrivialStrategy, }; diff --git a/lib/Strategies/TrivialStrategy.js b/lib/Strategies/TrivialStrategy.js index 1ae80d8..beae2db 100644 --- a/lib/Strategies/TrivialStrategy.js +++ b/lib/Strategies/TrivialStrategy.js @@ -15,11 +15,8 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); -var StrategyBase_1 = __importDefault(require("./StrategyBase")); +var StrategyBase_1 = require("./StrategyBase"); /** * This strategy uses a single sender for all configurations. * @@ -28,7 +25,7 @@ var StrategyBase_1 = __importDefault(require("./StrategyBase")); * @extends StrategyBase */ var TrivialStrategy = /** @class */ (function (_super) { - __extends(class_1, _super); + __extends(TrivialStrategy, _super); // noinspection JSClassNamingConvention /** * @constructor @@ -36,12 +33,12 @@ var TrivialStrategy = /** @class */ (function (_super) { * @param {function} sender * The Sender to use for all events */ - function class_1(sender) { + function TrivialStrategy(sender) { var _this = _super.call(this, false) || this; _this.senders = [sender]; return _this; } - return class_1; -}(StrategyBase_1.default)); -exports.default = TrivialStrategy; + return TrivialStrategy; +}(StrategyBase_1.StrategyBase)); +exports.TrivialStrategy = TrivialStrategy; //# sourceMappingURL=TrivialStrategy.js.map \ No newline at end of file diff --git a/lib/Strategies/TrivialStrategy.js.map b/lib/Strategies/TrivialStrategy.js.map index 90f071b..f8dc692 100644 --- a/lib/Strategies/TrivialStrategy.js.map +++ b/lib/Strategies/TrivialStrategy.js.map @@ -1 +1 @@ -{"version":3,"file":"TrivialStrategy.js","sourceRoot":"","sources":["../../src/Strategies/TrivialStrategy.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;AAIH,gEAA0C;AAE1C;;;;;;GAMG;AACH,IAAM,eAAe;IAAiB,2BAAY;IAChD,uCAAuC;IACvC;;;;;OAKG;IACH,iBAAY,MAAe;QAA3B,YACE,kBAAM,KAAK,CAAC,SAEb;QADC,KAAI,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC;;IAC1B,CAAC;IACH,cAAC;AAAD,CAAC,AAZuB,CAAc,sBAAY,EAYjD,CAAC;AAEF,kBAAe,eAAe,CAAC"} \ No newline at end of file +{"version":3,"file":"TrivialStrategy.js","sourceRoot":"","sources":["../../src/Strategies/TrivialStrategy.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;AAIH,+CAA8C;AAE9C;;;;;;GAMG;AACH;IAA8B,mCAAY;IACxC,uCAAuC;IACvC;;;;;OAKG;IACH,yBAAY,MAAe;QAA3B,YACE,kBAAM,KAAK,CAAC,SAEb;QADC,KAAI,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC;;IAC1B,CAAC;IACH,sBAAC;AAAD,CAAC,AAZD,CAA8B,2BAAY,GAYzC;AAGC,0CAAe"} \ No newline at end of file diff --git a/src/IContext.ts b/src/IContext.ts index 0f42234..85a4c79 100644 --- a/src/IContext.ts +++ b/src/IContext.ts @@ -1,36 +1,76 @@ -const DETAILS_KEY = "message_details"; -const HOST_KEY = "hostname"; -const SOURCE_KEY = "source"; -const TS_KEY = "timestamp"; +/** + * @fileOverview + * Basic data structures used during logging. + */ -interface IDetails { - [HOST_KEY]?: string; -} +const KEY_DETAILS = "message_details"; +const KEY_HOST = "hostname"; +const KEY_SOURCE = "source"; +const KEY_TS = "timestamp"; -interface ITimestamps { - // Values are times in milliseconds since the Epoch, e.g. +new Date(). - [op: string]: number; +/** + * The data accompanying a log event. + * + * - KEY_DETAILS: the details passed to the log() call by the application. + * - KEY_HOST: the host on which a hostname could first be found. This is + * usually the hostname of the Meteor server handling the request. + * - KEY_SOURCE: the source of the log event. In normal usage, it will be one of + * "client", "cordova", or "server", but can be any other string and tests, + * especially are expected to make use of other values. + * - KEY_TS: the timestamps chain taken while handling the log event. + * - "side" keys represent the additional context data added by processors on + * each side in a log chain. + * + * In practice, this means that log events emitted on a browser or mobile app + * will have two such keys: one for the source of the event ("client" or + * "cordova"), and one ("server") for the context added by the server handling + * the logging. Conversely, log events emitted on the server, e.g. during + * startup or a Meteor method call, will only have context added under the + * "server" key. + */ +interface IContext { + [KEY_DETAILS]?: IDetails; + [KEY_HOST]?: string; + [KEY_SOURCE]?: string; + [KEY_TS]?: ITimestamps; + [side: string]: {} | undefined; } -interface ITimestampsHash { - [side: string]: ITimestamps; +/** + * The type of data passed along the level and message in ILogger.log() calls. + * + * It is expected to mostly contain values for placeholders in the string + * representation of the message, in PSR-3 format (braces). + * + * @see IContext + */ +interface IDetails { + [key: string]: any; } -interface IContext { - [DETAILS_KEY]?: {}; - [HOST_KEY]?: string; - [SOURCE_KEY]?: string; - [TS_KEY]?: ITimestampsHash; - [key: string]: {} | undefined; +/** + * The time of the data under the KEY_TS in IContext. + * + * Its structure allows the conservation or relative time sequence on different + * hosts in a client->server or mobile->server chain by segregating timestamps + * by side performing the timestamping, avoiding issues with time drift in + * loosely coordinated hosts. + * + * @see IContext + */ +interface ITimestamps { + [side: string]: { + // Values are times in milliseconds since the Epoch, e.g. +new Date(). + [op: string]: number; + }; } export { - DETAILS_KEY, - HOST_KEY, - SOURCE_KEY, - TS_KEY, - IDetails, IContext, + IDetails, ITimestamps, - ITimestampsHash, + KEY_DETAILS, + KEY_HOST, + KEY_SOURCE, + KEY_TS, }; diff --git a/src/LogLevel.ts b/src/LogLevel.ts index a029782..bc98a64 100644 --- a/src/LogLevel.ts +++ b/src/LogLevel.ts @@ -1,5 +1,6 @@ /** - * @fileOverview Package exported constants. + * @fileOverview + * Package exported constants. */ const Names = [ diff --git a/src/Loggers/ClientLogger.ts b/src/Loggers/ClientLogger.ts index 7811b3e..ea913a8 100644 --- a/src/Loggers/ClientLogger.ts +++ b/src/Loggers/ClientLogger.ts @@ -12,13 +12,8 @@ const SIDE = "client"; * * In its current state, it brings nothing over Logger, simply providing an * extension-specialization point. - * - * @extends Logger - * - * @property {string} side */ class ClientLogger extends Logger { - public static readonly side = SIDE; constructor(strategy: IStrategy) { super(strategy); @@ -35,4 +30,5 @@ class ClientLogger extends Logger { export { ClientLogger, + SIDE as ClientSide, }; diff --git a/src/Loggers/ILogger.ts b/src/Loggers/ILogger.ts index 5c834ad..2ccca56 100644 --- a/src/Loggers/ILogger.ts +++ b/src/Loggers/ILogger.ts @@ -1,4 +1,4 @@ -import {IContext} from "../IContext"; +import {IContext, IDetails} from "../IContext"; import * as LogLevel from "../LogLevel"; interface ILogger { @@ -24,7 +24,7 @@ interface ILogger { * @see https://tools.ietf.org/html/rfc5424 * @see http://www.php-fig.org/psr/psr-3/ */ - log(level: LogLevel.Levels, message: string, context: IContext): void; + log(level: LogLevel.Levels, message: string, context: IDetails): void; /** * Implementation compatibility to replace Meteor.debug. diff --git a/src/Loggers/Logger.ts b/src/Loggers/Logger.ts index ffa2c6c..1295b8b 100644 --- a/src/Loggers/Logger.ts +++ b/src/Loggers/Logger.ts @@ -5,10 +5,12 @@ import TraceKit from "tracekit"; import { - DETAILS_KEY, HOST_KEY, IContext, - ITimestampsHash, SOURCE_KEY, - TS_KEY, + ITimestamps, + KEY_DETAILS, + KEY_HOST, + KEY_SOURCE, + KEY_TS, } from "../IContext"; import InvalidArgumentException from "../InvalidArgumentException"; import * as LogLevel from "../LogLevel"; @@ -49,25 +51,27 @@ class Logger implements ILogger { /** * Add a timestamp to a context object on the active side. * - * Ensure a TS_KEY will be present, and existing timestamps are not being - * overwritten, except possibly for any value already present at [TS_KEY][op]. + * Ensure a KEY_TS will be present, and existing timestamps are not being + * overwritten, except possibly for any value already present at [KEY_TS][op]. * * @param context * Mutated. The context to stamp. * @param op * The operation for which to add a timestamp. + * @param side + * The side on which the operation is to be logged. * * @protected */ - public static stamp(context: IContext, op: string, side: keyof ITimestampsHash): void { + public static stamp(context: IContext, op: string, side: keyof ITimestamps): void { const now = + new Date(); - // Ensure context actually contains a TS_KEY. - if (typeof context[TS_KEY] === "undefined") { - context[TS_KEY] = {} as ITimestampsHash; + // Ensure context actually contains a KEY_TS. + if (typeof context[KEY_TS] === "undefined") { + context[KEY_TS] = {} as ITimestamps; } - // We know context[TS_KEY] is defined because we just ensured it was. - const contextTs: ITimestampsHash = context[TS_KEY]!; + // We know context[KEY_TS] is defined because we just ensured it was. + const contextTs: ITimestamps = context[KEY_TS]!; const sideTs = contextTs[side] || {}; sideTs[op] = now; @@ -145,13 +149,13 @@ class Logger implements ILogger { */ public getInitialContext(details = {}): IContext { const cx: IContext = { - [DETAILS_KEY]: details, - [SOURCE_KEY]: this.side, + [KEY_DETAILS]: details, + [KEY_SOURCE]: this.side, }; const hostName = this._getHostname(); if (typeof hostName === "string") { - cx[HOST_KEY] = hostName; + cx[KEY_HOST] = hostName; } Logger.stamp(cx, "log", this.side); diff --git a/src/Loggers/ServerLogger.ts b/src/Loggers/ServerLogger.ts index acebd65..44d154d 100644 --- a/src/Loggers/ServerLogger.ts +++ b/src/Loggers/ServerLogger.ts @@ -11,10 +11,16 @@ import * as os from "os"; import process from "process"; import * as util from "util"; // Package imports. -import {DETAILS_KEY, HOST_KEY, IContext, SOURCE_KEY } from "../IContext"; +import { + KEY_DETAILS, + KEY_HOST, + IContext, + IDetails, + KEY_SOURCE +} from "../IContext"; import * as LogLevel from "../LogLevel"; import {IStrategy} from "../Strategies/IStrategy"; -import {ClientLogger} from "./ClientLogger"; +import {ClientSide} from "./ClientLogger"; import {ILogger} from "./ILogger"; import {Logger} from "./Logger"; import WriteStream = NodeJS.WriteStream; @@ -200,8 +206,8 @@ class ServerLogger extends Logger implements ILogger { */ public defaultContext(initialContext: IContext, source: string): IContext { const cx1 = { - [HOST_KEY]: this._getHostname(), - [SOURCE_KEY]: source, + [KEY_HOST]: this._getHostname(), + [KEY_SOURCE]: source, ...initialContext, }; Logger.stamp(cx1, "log", this.side); @@ -254,11 +260,11 @@ class ServerLogger extends Logger implements ILogger { context.requestHeaders = req.headers; } const { - [DETAILS_KEY]: details, + [KEY_DETAILS]: details, // tslint:disable-next-line ...nonDetails } = context; - this.logExtended(level, message, nonDetails, ClientLogger.side); + this.logExtended(level, message, nonDetails, ClientSide); res.statusCode = 200; result = ""; } catch (err) { @@ -275,7 +281,7 @@ class ServerLogger extends Logger implements ILogger { /** * @inheritDoc */ - public log(level: LogLevel.Levels, message: string, rawContext: IContext): void { + public log(level: LogLevel.Levels, message: string, rawContext: IDetails): void { rawContext.hostname = this.hostname; super.log(level, message, rawContext); } @@ -315,7 +321,7 @@ class ServerLogger extends Logger implements ILogger { * @returns {void} */ public logMethod({ level = LogLevel.INFO, message = "", context = {} }) { - this.logExtended(level, message, context, ClientLogger.side); + this.logExtended(level, message, context, ClientSide); } /** diff --git a/src/Loggers/index.ts b/src/Loggers/index.ts index 45585a9..aa016cf 100644 --- a/src/Loggers/index.ts +++ b/src/Loggers/index.ts @@ -1,26 +1,27 @@ +import { IContext, IDetails, ITimestamps, KEY_DETAILS, KEY_HOST, KEY_SOURCE, KEY_TS } from "../IContext"; import InvalidArgumentException from "../InvalidArgumentException"; import * as LogLevel from "../LogLevel"; import { ClientLogger } from "./ClientLogger"; +import { ILogger } from "./ILogger"; import { Logger } from "./Logger"; import { ServerLogger } from "./ServerLogger"; import { BrowserProcessor } from "../Processors/BrowserProcessor"; -import MeteorUserProcessor from "../Processors/MeteorUserProcessor"; -import ProcessorBase from "../Processors/ProcessorBase"; -import RoutingProcessor from "../Processors/RoutingProcessor"; - -import LeveledStrategy from "../Strategies/LeveledStrategy"; -import StrategyBase from "../Strategies/StrategyBase"; -import TrivialStrategy from "../Strategies/TrivialStrategy"; - -import ConsoleSender from "../Senders/ConsoleSender"; -import MeteorClientHttpSender from "../Senders/MeteorClientHttpSender"; -import MeteorClientMethodSender from "../Senders/MeteorClientMethodSender"; -import MongodbSender from "../Senders/MongodbSender"; -import NullSender from "../Senders/NullSender"; -import { SenderBase } from "../Senders/SenderBase"; -import TeeSender from "../Senders/TeeSender"; +import { MeteorUserProcessor } from "../Processors/MeteorUserProcessor"; +import { ProcessorBase } from "../Processors/ProcessorBase"; +import { RoutingProcessor } from "../Processors/RoutingProcessor"; + +import { LeveledStrategy } from "../Strategies/LeveledStrategy"; +import { StrategyBase } from "../Strategies/StrategyBase"; +import { TrivialStrategy } from "../Strategies/TrivialStrategy"; + +import { ConsoleSender } from "../Senders/ConsoleSender"; +import { MeteorClientHttpSender } from "../Senders/MeteorClientHttpSender"; +import { MeteorClientMethodSender } from "../Senders/MeteorClientMethodSender"; +import { MongodbSender } from "../Senders/MongodbSender"; +import { NullSender } from "../Senders/NullSender"; +import { TeeSender } from "../Senders/TeeSender"; /* modern-syslog is not usable on the client side, because it fails to load * its compiled binary dependency, hence the dynamic require and tslint disable. @@ -29,13 +30,24 @@ import TeeSender from "../Senders/TeeSender"; */ const SyslogSender = Meteor.isServer // tslint:disable-next-line - ? require("../Senders/SyslogSender").default + ? require("../Senders/SyslogSender").SyslogSender : NullSender; export { + // Context. + IContext, + IDetails, + ITimestamps, + KEY_DETAILS, + KEY_HOST, + KEY_SOURCE, + KEY_TS, + InvalidArgumentException, LogLevel, + // Loggers. + ILogger, Logger, ClientLogger, ServerLogger, @@ -51,8 +63,6 @@ export { LeveledStrategy, TrivialStrategy, - // SenderBase is the "abstract" base class from which to extend custom senders. - SenderBase, NullSender, ConsoleSender, MeteorClientHttpSender, diff --git a/src/Processors/BrowserProcessor.ts b/src/Processors/BrowserProcessor.ts index 89250d9..2ef3401 100644 --- a/src/Processors/BrowserProcessor.ts +++ b/src/Processors/BrowserProcessor.ts @@ -3,7 +3,7 @@ */ import {IContext} from "../IContext"; import {IProcessor} from "./IProcessor"; -import ProcessorBase from "./ProcessorBase"; +import { ProcessorBase } from "./ProcessorBase"; interface IMemoryInfo { jsHeapSizeLimit: number; @@ -41,7 +41,7 @@ interface INavigator { * * @extends ProcessorBase */ -const BrowserProcessor = class extends ProcessorBase implements IProcessor { +class BrowserProcessor extends ProcessorBase implements IProcessor { public navigator: INavigator; public window: IWindow; @@ -104,7 +104,7 @@ const BrowserProcessor = class extends ProcessorBase implements IProcessor { return result; } -}; +} export { BrowserProcessor, diff --git a/src/Processors/IProcessor.ts b/src/Processors/IProcessor.ts index fe827c4..b97607e 100644 --- a/src/Processors/IProcessor.ts +++ b/src/Processors/IProcessor.ts @@ -1,4 +1,4 @@ -import {IContext} from "../IContext"; +import { IContext } from "../IContext"; interface IProcessor { /** diff --git a/src/Processors/MeteorUserProcessor.ts b/src/Processors/MeteorUserProcessor.ts index 65f6584..adbe461 100644 --- a/src/Processors/MeteorUserProcessor.ts +++ b/src/Processors/MeteorUserProcessor.ts @@ -5,11 +5,11 @@ */ import {IProcessor} from "./IProcessor"; -import ProcessorBase from "./ProcessorBase"; +import { ProcessorBase } from "./ProcessorBase"; import stack from "callsite"; import User = Meteor.User; -import {IContext, SOURCE_KEY} from "../IContext"; +import {IContext, KEY_SOURCE} from "../IContext"; interface IPackage { "accounts-base": { @@ -28,7 +28,7 @@ declare var Package: IPackage; * * @extends ProcessorBase */ -const MeteorUserProcessor = class extends ProcessorBase implements IProcessor { +class MeteorUserProcessor extends ProcessorBase implements IProcessor { public platform: string; public userCache: { [key: string]: object }; @@ -182,7 +182,7 @@ const MeteorUserProcessor = class extends ProcessorBase implements IProcessor { // mobile information, a straight server-side log context is not rebuilt by // a call to logExtended, so it needs to be set directly in place under a // platform key. - const userContext = (context[SOURCE_KEY] === this.platform) + const userContext = (context[KEY_SOURCE] === this.platform) ? { [this.platform]: { user } } : { user }; let result = Object.assign({}, context, userContext); @@ -193,6 +193,8 @@ const MeteorUserProcessor = class extends ProcessorBase implements IProcessor { return result; } -}; +} -export default MeteorUserProcessor; +export { + MeteorUserProcessor, +}; diff --git a/src/Processors/ProcessorBase.ts b/src/Processors/ProcessorBase.ts index f4735b0..b9ac1de 100644 --- a/src/Processors/ProcessorBase.ts +++ b/src/Processors/ProcessorBase.ts @@ -10,11 +10,13 @@ import {IProcessor} from "./IProcessor"; * * It exists only to document the processor interface. */ -const ProcessorBase = class implements IProcessor { +class ProcessorBase implements IProcessor { /** @inheritDoc */ public process(context: IContext): IContext { return context as IContext; } -}; +} -export default ProcessorBase; +export { + ProcessorBase, +}; diff --git a/src/Processors/RoutingProcessor.ts b/src/Processors/RoutingProcessor.ts index be340c6..a000e85 100644 --- a/src/Processors/RoutingProcessor.ts +++ b/src/Processors/RoutingProcessor.ts @@ -3,14 +3,14 @@ */ import {IContext} from "../IContext"; import {IProcessor} from "./IProcessor"; -import ProcessorBase from "./ProcessorBase"; +import { ProcessorBase } from "./ProcessorBase"; /** * RoutingProcessor adds route information to logs. * * @extends ProcessorBase */ -const RoutingProcessor = class extends ProcessorBase implements IProcessor { +class RoutingProcessor extends ProcessorBase implements IProcessor { /** * Constructor ensures the processor is used in a browser context. */ @@ -34,6 +34,8 @@ const RoutingProcessor = class extends ProcessorBase implements IProcessor { const result = Object.assign({}, context, { routing: { location: window.location } }); return result; } -}; +} -export default RoutingProcessor; +export { + RoutingProcessor, +}; diff --git a/src/Senders/ConsoleSender.ts b/src/Senders/ConsoleSender.ts index 19a9b4b..96bcfef 100644 --- a/src/Senders/ConsoleSender.ts +++ b/src/Senders/ConsoleSender.ts @@ -6,19 +6,16 @@ */ /* tslint:disable:no-console */ +import {IContext} from "../IContext"; import * as LogLevel from "../LogLevel"; import {ISender} from "./ISender"; -import { SenderBase } from "./SenderBase"; /** * ConsoleSender sends the log events it receives to the browser console. - * - * @extends SenderBase */ -const ConsoleSender = class extends SenderBase implements ISender { +class ConsoleSender implements ISender { constructor() { - super(); - // Checkint "if (!(console instanceof Console)" compiles, but fails to + // Checking "if (!(console instanceof Console)" compiles, but fails to // execute during tests, which run in Node.JS in which Console is not a type // but only the name of the console constructor. Since checking // console.constructor.name is liable to fail in minified code, we need a @@ -37,7 +34,7 @@ const ConsoleSender = class extends SenderBase implements ISender { } /** @inheritDoc */ - public send(level: LogLevel.Levels, message: string, context: object) { + public send(level: LogLevel.Levels, message: string, context: IContext) { const methods = [ console.error, console.error, @@ -52,6 +49,8 @@ const ConsoleSender = class extends SenderBase implements ISender { const method = methods[level].bind(console); method(LogLevel.Names[level], message, context); } -}; +} -export default ConsoleSender; +export { + ConsoleSender, +}; diff --git a/src/Senders/ISender.ts b/src/Senders/ISender.ts index 224f011..3a1b2bf 100644 --- a/src/Senders/ISender.ts +++ b/src/Senders/ISender.ts @@ -1,3 +1,4 @@ +import {IContext} from "../IContext"; import * as LogLevel from "../LogLevel"; interface ISender { @@ -11,7 +12,7 @@ interface ISender { * @param context * A log event context object. */ - send(level: LogLevel.Levels, message: string, context: object): void; + send(level: LogLevel.Levels, message: string, context: IContext): void; } export { diff --git a/src/Senders/MeteorClientHttpSender.ts b/src/Senders/MeteorClientHttpSender.ts index 992e9ab..fa7cdfc 100644 --- a/src/Senders/MeteorClientHttpSender.ts +++ b/src/Senders/MeteorClientHttpSender.ts @@ -5,14 +5,12 @@ */ import NullFn from "../NullFn"; -import { SenderBase } from "./SenderBase"; +import {ISender} from "./ISender"; /** * MeteorClientHttpSender send data from the client to the server over HTTP. - * - * @extends SenderBase */ -const MeteorClientHttpSender = class extends SenderBase { +class MeteorClientHttpSender implements ISender { public http: typeof HTTP; public requestHeaders: { [key: string]: string }; @@ -24,7 +22,6 @@ const MeteorClientHttpSender = class extends SenderBase { * The absolute URL of the logger server. Usually /logger on the Meteor app. */ constructor(public loggerUrl: string) { - super(); if (typeof Meteor === "undefined" || !Meteor.isClient) { throw new Error("MeteorClientHttpSender is only meant for Meteor client side."); } @@ -51,6 +48,8 @@ const MeteorClientHttpSender = class extends SenderBase { }; this.http.post(this.loggerUrl, options, NullFn); } -}; +} -export default MeteorClientHttpSender; +export { + MeteorClientHttpSender, +}; diff --git a/src/Senders/MeteorClientMethodSender.ts b/src/Senders/MeteorClientMethodSender.ts index 3b609f1..651b52d 100644 --- a/src/Senders/MeteorClientMethodSender.ts +++ b/src/Senders/MeteorClientMethodSender.ts @@ -5,22 +5,14 @@ */ import { Logger } from "../Loggers/Logger"; -import { SenderBase } from "./SenderBase"; +import {ISender} from "./ISender"; /** * MeteorClientMethodSender send data from the client to the server over DDP. - * - * @extends SenderBase */ -const MeteorClientMethodSender = class extends SenderBase { - /** - * @constructor - * - * @param {String} loggerUrl - * The absolute URL of the logger server. Usually /logger on the Meteor app. - */ +class MeteorClientMethodSender implements ISender { + constructor() { - super(); if (typeof Meteor === "undefined" || !Meteor.isClient) { throw new Error("MeteorClientMethodSender is only meant for Meteor client side."); } @@ -35,6 +27,8 @@ const MeteorClientMethodSender = class extends SenderBase { Meteor.call(Logger.METHOD, data); } -}; +} -export default MeteorClientMethodSender; +export { + MeteorClientMethodSender, +}; diff --git a/src/Senders/MongodbSender.ts b/src/Senders/MongodbSender.ts index bb0e3ec..d99b9ae 100644 --- a/src/Senders/MongodbSender.ts +++ b/src/Senders/MongodbSender.ts @@ -2,57 +2,56 @@ * @fileOverview MongoDB Sender class. */ import {Mongo} from "meteor/mongo"; -import {IContext, TS_KEY} from "../IContext"; -import { Logger } from "../Loggers/Logger"; -import { ServerSide } from "../Loggers/ServerLogger"; -import { SenderBase } from "./SenderBase"; +import {IContext, ITimestamps, KEY_TS} from "../IContext"; +import {Logger} from "../Loggers/Logger"; +import {ServerSide} from "../Loggers/ServerLogger"; +import * as LogLevel from "../LogLevel"; +import {ISender} from "./ISender"; /** * MongodbSender sends logs to the Meteor standard database. - * - * @extends SenderBase */ -const MongodbSender = class extends SenderBase { +class MongodbSender implements ISender { public store: Mongo.Collection; // noinspection JSClassNamingConvention /** * @constructor * - * @param {Mongo} mongo + * @param mongo * The Meteor Mongo service. - * @param {(String|Collection)} collection + * @param collection * The collection or the name of the collection in which to log. */ constructor(mongo: any, collection: string|Mongo.Collection = "logger") { - super(); if (collection instanceof mongo.Collection) { this.store = collection as Mongo.Collection; } else if (typeof collection === "string") { - const collectionName = collection; - this.store = new mongo.Collection(collectionName); + this.store = new mongo.Collection(collection); } else { throw new Error("MongodbSender requires a Collection or a collection name"); } } /** @inheritDoc */ - public send(level: number, message: string, context: object): void { + public send(level: LogLevel.Levels, message: string, context: IContext): void { const defaultedContext: IContext = { ...context, timestamp: {} }; const doc = { level, message, context: {} as IContext }; // It should contain a timestamp.{side} object if it comes from any Logger. - if (typeof defaultedContext[TS_KEY] === "undefined") { - defaultedContext[TS_KEY] = { + if (typeof defaultedContext[KEY_TS] === "undefined") { + defaultedContext[KEY_TS] = { server: {}, }; } doc.context = defaultedContext; // doc.context.timestamp.server is known to exist from above. - Logger.stamp(doc.context, "send", ServerSide); + Logger.stamp(doc.context, "send", ServerSide as keyof ITimestamps); this.store.insert(doc); } -}; +} -export default MongodbSender; +export { + MongodbSender, +}; diff --git a/src/Senders/NullSender.ts b/src/Senders/NullSender.ts index 2e5fa6a..696634e 100644 --- a/src/Senders/NullSender.ts +++ b/src/Senders/NullSender.ts @@ -2,16 +2,21 @@ * @fileOverview NulllSender class. */ -import { SenderBase } from "./SenderBase"; +import {ISender} from "./ISender"; +import {IContext} from "../IContext"; +import * as LogLevel from "../LogLevel"; /** * NullSender defines an explicit null sender. - * - * Although SenderBase is also null, this is not its defining characteristic - * hence this alias. - * - * @extends SenderBase */ -const NullSender = class extends SenderBase {}; +class NullSender implements ISender { + /** @inheritDoc */ + public send(_1: LogLevel.Levels, _2: string, _3: IContext): void { + // Explicit return is needed to avoid the TSlint no-empty warning. + return; + } +} -export default NullSender; +export { + NullSender, +}; diff --git a/src/Senders/SenderBase.ts b/src/Senders/SenderBase.ts index fb10f81..3d634ef 100644 --- a/src/Senders/SenderBase.ts +++ b/src/Senders/SenderBase.ts @@ -1,7 +1,9 @@ /** - * @fileOverview Base Sender class. + * @fileOverview + * Base Sender class. */ +import {IContext} from "../IContext"; import * as LogLevel from "../LogLevel"; import {ISender} from "./ISender"; @@ -10,7 +12,7 @@ import {ISender} from "./ISender"; */ class SenderBase implements ISender { /** @inheritDoc */ - public send(_1: LogLevel.Levels, _2: string, _3: object): void { return; } + public send(_1: LogLevel.Levels, _2: string, _3: IContext): void { return; } } export { diff --git a/src/Senders/SyslogSender.ts b/src/Senders/SyslogSender.ts index d54c5a4..3af8730 100644 --- a/src/Senders/SyslogSender.ts +++ b/src/Senders/SyslogSender.ts @@ -5,11 +5,11 @@ import modernSyslog = require("modern-syslog"); import * as path from "path"; import * as util from "util"; -import {IContext, TS_KEY} from "../IContext"; -import { Logger } from "../Loggers/Logger"; +import {IContext, KEY_TS} from "../IContext"; +import {Logger} from "../Loggers/Logger"; +import {ServerLogger} from "../Loggers/ServerLogger"; import * as LogLevel from "../LogLevel"; -import { ServerLogger } from "../Loggers/ServerLogger"; -import { SenderBase } from "./SenderBase"; +import {ISender} from "./ISender"; type Serializer = (doc: object) => string; @@ -30,10 +30,8 @@ interface ISyslogContext { * @see https://tools.ietf.org/html/rfc3164#section-4.1 * @see https://tools.ietf.org/html/rfc5424#section-6.1 * @see https://tools.ietf.org/html/rfc6587#section-3.4.1 - * - * @extends SenderBase */ -const SyslogSender = class extends SenderBase { +class SyslogSender implements ISender { public facility: number; public formatOptions: object; public ident: string; @@ -66,11 +64,10 @@ const SyslogSender = class extends SenderBase { ident = null, syslogOptions: number = 0, syslogFacility: number | null = null, - public syslog: any, //modernSyslog, + public syslog: any, // modernSyslog, formatOptions = null, serialize = null, ) { - super(); const programName = path.basename(process.argv[1]); const actualIdent = ident || programName; @@ -100,9 +97,9 @@ const SyslogSender = class extends SenderBase { } // It should contain a timestamp.{side} object if it comes from any Logger. if (typeof doc.context === "undefined") { - doc.context = { [TS_KEY]: { server: {}}}; - } else if (typeof doc.context[TS_KEY] === "undefined") { - doc.context[TS_KEY] = {}; + doc.context = { [KEY_TS]: { server: {}}}; + } else if (typeof doc.context[KEY_TS] === "undefined") { + doc.context[KEY_TS] = {}; } // doc.context.timestamp.server is known to exist from above. @@ -143,9 +140,8 @@ const SyslogSender = class extends SenderBase { raw: util.inspect(doc, this.formatOptions), }; - if (typeof doc.message === "string") { - step1.message = doc.message; - } + // Since doc is a SyslogContext, doc.message is a string, no need to test. + step1.message = doc.message; try { result = JSON.stringify(step1); @@ -170,9 +166,10 @@ const SyslogSender = class extends SenderBase { * The serialized version of the doc argument under the formatOptions rules. */ public serializeInspect(doc: object): string { - const result = util.inspect(doc, this.formatOptions); - return result; + return util.inspect(doc, this.formatOptions); } -}; +} -export default SyslogSender; +export { + SyslogSender, +}; diff --git a/src/Senders/TeeSender.ts b/src/Senders/TeeSender.ts index 9110082..d3a10c3 100644 --- a/src/Senders/TeeSender.ts +++ b/src/Senders/TeeSender.ts @@ -2,29 +2,28 @@ * @fileOverview Tee Sender class. */ +import {IContext} from "../IContext"; +import * as LogLevel from "../LogLevel"; import {ISender} from "./ISender"; -import { SenderBase } from "./SenderBase"; /** * Like a UNIX tee(1), the TeeSender sends its input to multiple outputs. - * - * @extends SenderBase */ -const TeeSender = class extends SenderBase implements ISender { +class TeeSender implements ISender { /** * Constructor. * * @param {Array} senders * An array of senders to which to send the input. */ - constructor(public senders: ISender[]) { - super(); - } + constructor(public senders: ISender[]) {} /** @inheritdoc */ - public send(level: number, message: string, context: object): void { + public send(level: LogLevel.Levels, message: string, context: IContext): void { this.senders.map((sender) => sender.send(level, message, context)); } -}; +} -export default TeeSender; +export { + TeeSender, +}; diff --git a/src/Strategies/IStrategy.ts b/src/Strategies/IStrategy.ts index 5e3d98b..783faea 100644 --- a/src/Strategies/IStrategy.ts +++ b/src/Strategies/IStrategy.ts @@ -1,3 +1,4 @@ +import {IContext} from "../IContext"; import {ILogger} from "../Loggers/ILogger"; import * as LogLevel from "../LogLevel"; import {ISender} from "../Senders/ISender"; @@ -16,7 +17,7 @@ interface IStrategy { * @returns * An array of senders to use for this event. */ - selectSenders(level: LogLevel.Levels, message: string, context: object): ISender[]; + selectSenders(level: LogLevel.Levels, message: string, context: IContext): ISender[]; /** * This method may modify the logger methods, e.g. to do nothing on debug. diff --git a/src/Strategies/LeveledStrategy.ts b/src/Strategies/LeveledStrategy.ts index 761a036..d64642c 100644 --- a/src/Strategies/LeveledStrategy.ts +++ b/src/Strategies/LeveledStrategy.ts @@ -2,20 +2,21 @@ * @fileOverview Level-based Strategy. */ +import {IContext} from "../IContext"; import {ILogger} from "../Loggers/ILogger"; import * as LogLevel from "../LogLevel"; import NullFn from "../NullFn"; import {ISender} from "../Senders/ISender"; -import NullSender from "../Senders/NullSender"; -import { SenderBase } from "../Senders/SenderBase"; -import StrategyBase from "./StrategyBase"; +import { NullSender } from "../Senders/NullSender"; +import {IStrategy} from "./IStrategy"; +import { StrategyBase } from "./StrategyBase"; /** * LeveledStrategy defines a single sender per level. * * @extends StrategyBase */ -const LeveledStrategy = class extends StrategyBase { +class LeveledStrategy extends StrategyBase implements IStrategy { // noinspection JSClassNamingConvention /** @@ -43,12 +44,14 @@ const LeveledStrategy = class extends StrategyBase { this.senders = [low, medium, high]; this.senders.forEach((sender) => { - if (!(sender instanceof SenderBase)) { - throw new Error("LeveledStrategy: senders must be instances of a Sender class."); + // Not really an "implements ISender" check, but cheaper and more useful. + if (!sender.send) { + throw new Error(`LeveledStrategy: senders must implement the ISender "send()" method.`); } }); } + /** @inheritDoc */ public customizeLogger(logger: ILogger): void { ["low", "medium", "high"].forEach((level) => { if (this[level as keyof this] instanceof NullSender) { @@ -57,7 +60,7 @@ const LeveledStrategy = class extends StrategyBase { }); } - public selectSenders(level: LogLevel.Levels, _2: string, _3: object) { + public selectSenders(level: LogLevel.Levels, _2: string, _3: IContext): ISender[] { let sender; if (level >= this.minLow) { sender = this.low; @@ -69,6 +72,8 @@ const LeveledStrategy = class extends StrategyBase { return [sender]; } -}; +} -export default LeveledStrategy; +export { + LeveledStrategy, +}; diff --git a/src/Strategies/StrategyBase.ts b/src/Strategies/StrategyBase.ts index 473f71a..ae3ad35 100644 --- a/src/Strategies/StrategyBase.ts +++ b/src/Strategies/StrategyBase.ts @@ -5,17 +5,15 @@ import {ILogger} from "../Loggers/ILogger"; import * as LogLevel from "../LogLevel"; import {ISender} from "../Senders/ISender"; -import NullSender from "../Senders/NullSender"; +import { NullSender } from "../Senders/NullSender"; import {IStrategy} from "./IStrategy"; /** * StrategyBase is an "abstract" strategy. * * Strategies customize the active Sender instances for a given log event. - * - * @see SenderBase */ -const StrategyBase = class implements IStrategy { +class StrategyBase implements IStrategy { // @see https://github.com/Microsoft/TypeScript/issues/17293 public senders: ISender[] = []; @@ -26,11 +24,15 @@ const StrategyBase = class implements IStrategy { } } + /** @inheritDoc */ public selectSenders(_1: LogLevel.Levels, _2: string, _3: object) { return this.senders; } + /** @inheritDoc */ public customizeLogger(_: ILogger): void { return; } -}; +} -export default StrategyBase; +export { + StrategyBase, +}; diff --git a/src/Strategies/TrivialStrategy.ts b/src/Strategies/TrivialStrategy.ts index 61fe03f..c54044d 100644 --- a/src/Strategies/TrivialStrategy.ts +++ b/src/Strategies/TrivialStrategy.ts @@ -4,7 +4,7 @@ import {ISender} from "../Senders/ISender"; import {IStrategy} from "./IStrategy"; -import StrategyBase from "./StrategyBase"; +import { StrategyBase } from "./StrategyBase"; /** * This strategy uses a single sender for all configurations. @@ -13,7 +13,7 @@ import StrategyBase from "./StrategyBase"; * * @extends StrategyBase */ -const TrivialStrategy = class extends StrategyBase implements IStrategy { +class TrivialStrategy extends StrategyBase implements IStrategy { // noinspection JSClassNamingConvention /** * @constructor @@ -25,6 +25,8 @@ const TrivialStrategy = class extends StrategyBase implements IStrategy { super(false); this.senders = [sender]; } -}; +} -export default TrivialStrategy; +export { + TrivialStrategy, +};