@node-ts/logger-core
Advanced tools
Comparing version
@@ -21,3 +21,3 @@ "use strict"; | ||
// tslint:disable-next-line:no-unsafe-any Node typings | ||
log(this.jsConsole.debug.bind(this), this.name, message, data); | ||
log(this.jsConsole.trace.bind(this), this.name, message, data); | ||
} | ||
@@ -24,0 +24,0 @@ info(message, data) { |
@@ -20,3 +20,3 @@ "use strict"; | ||
}); | ||
it('should log trace to debug', () => { | ||
it('should log trace to trace', () => { | ||
sut.trace(message, data); | ||
@@ -23,0 +23,0 @@ jsConsole.verify(c => c.trace(expectedMessage, data), typemoq_1.Times.once()); |
"use strict"; | ||
// tslint:disable:max-classes-per-file | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
// tslint:disable:max-classes-per-file no-unsafe-any no-any | ||
const inversify_1 = require("inversify"); | ||
@@ -10,3 +10,2 @@ const logger_module_1 = require("./logger-module"); | ||
const typemoq_1 = require("typemoq"); | ||
const console_logger_1 = require("./console-logger"); | ||
let TestClass = class TestClass { | ||
@@ -33,6 +32,9 @@ constructor(logger) { | ||
consoleLogger = typemoq_1.Mock.ofType(); | ||
container.bind(logger_symbols_1.LOGGER_SYMBOLS.Logger).toConstantValue(consoleLogger.object); | ||
const factory = typemoq_1.Mock.ofType(); | ||
factory | ||
.setup(f => f.build(TestClass.name, typemoq_1.It.isAny())) | ||
.returns(() => consoleLogger.object); | ||
container.rebind(logger_symbols_1.LOGGER_SYMBOLS.LoggerFactory).toConstantValue(factory.object); | ||
container.bind(TestClass).to(TestClass); | ||
// tslint:disable-next-line:no-unbound-method no-unsafe-any no-invalid-this | ||
bind_logger_1.bindLogger(container.bind, TestClass); | ||
bind_logger_1.bindLogger((serviceIdentifier) => container.bind(serviceIdentifier), TestClass); | ||
testClass = container.get(TestClass); | ||
@@ -42,3 +44,3 @@ }); | ||
it('should inject console based loggers', () => { | ||
expect(testClass.logger).toBeInstanceOf(console_logger_1.ConsoleLogger); | ||
expect(testClass.logger).toEqual(consoleLogger.object); | ||
}); | ||
@@ -45,0 +47,0 @@ }); |
{ | ||
"name": "@node-ts/logger-core", | ||
"version": "0.0.17", | ||
"version": "0.1.0", | ||
"description": "Defines a logging adapter contract between consumers and implementations", | ||
@@ -36,3 +36,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "b3f992202b4edd559c960d7134e08dfda459f39d" | ||
"gitHead": "d11d90bce28df0fad516cdc8ada8b584a5bbbe49" | ||
} |
@@ -1,2 +0,1 @@ | ||
import { Logger } from './logger' | ||
import { interfaces } from 'inversify' | ||
@@ -15,3 +14,3 @@ import { LOGGER_SYMBOLS } from './logger-symbols' | ||
export function bindLogger<T> (bind: interfaces.Bind, type: ClassConstructor<T>): void { | ||
bind<Logger>(LOGGER_SYMBOLS.Logger) | ||
bind(LOGGER_SYMBOLS.Logger) | ||
.toDynamicValue(context => { | ||
@@ -18,0 +17,0 @@ const factory = context.container.get<LoggerFactory>(LOGGER_SYMBOLS.LoggerFactory) |
@@ -30,3 +30,3 @@ import { ConsoleLogger } from './console-logger' | ||
it('should log trace to debug', () => { | ||
it('should log trace to trace', () => { | ||
sut.trace(message, data) | ||
@@ -33,0 +33,0 @@ jsConsole.verify( |
@@ -25,3 +25,3 @@ import { Logger } from './logger' | ||
// tslint:disable-next-line:no-unsafe-any Node typings | ||
log(this.jsConsole.debug.bind(this), this.name, message, data) | ||
log(this.jsConsole.trace.bind(this), this.name, message, data) | ||
} | ||
@@ -28,0 +28,0 @@ |
@@ -1,3 +0,2 @@ | ||
// tslint:disable:max-classes-per-file | ||
// tslint:disable:max-classes-per-file no-unsafe-any no-any | ||
import { Container, injectable, inject } from 'inversify' | ||
@@ -8,4 +7,5 @@ import { LoggerModule } from './logger-module' | ||
import { bindLogger } from './bind-logger' | ||
import { IMock, Times, Mock } from 'typemoq' | ||
import { IMock, Times, Mock, It } from 'typemoq' | ||
import { ConsoleLogger } from './console-logger' | ||
import { ConsoleLoggerFactory } from './console-logger-factory' | ||
@@ -34,7 +34,14 @@ @injectable() | ||
consoleLogger = Mock.ofType<ConsoleLogger>() | ||
container.bind(LOGGER_SYMBOLS.Logger).toConstantValue(consoleLogger.object) | ||
const factory = Mock.ofType<ConsoleLoggerFactory>() | ||
factory | ||
.setup(f => f.build(TestClass.name, It.isAny())) | ||
.returns(() => consoleLogger.object) | ||
container.rebind(LOGGER_SYMBOLS.LoggerFactory).toConstantValue(factory.object) | ||
container.bind(TestClass).to(TestClass) | ||
// tslint:disable-next-line:no-unbound-method no-unsafe-any no-invalid-this | ||
bindLogger(container.bind, TestClass) | ||
bindLogger( | ||
(serviceIdentifier: any) => container.bind(serviceIdentifier), | ||
TestClass | ||
) | ||
testClass = container.get(TestClass) | ||
@@ -45,3 +52,3 @@ }) | ||
it('should inject console based loggers', () => { | ||
expect(testClass.logger).toBeInstanceOf(ConsoleLogger) | ||
expect(testClass.logger).toEqual(consoleLogger.object) | ||
}) | ||
@@ -48,0 +55,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37617
1.46%573
1.42%