From 166671735ece776722f3572e76daad6d0f9a3a5c Mon Sep 17 00:00:00 2001 From: Federico Pinna Date: Tue, 9 May 2017 10:25:51 +0200 Subject: [PATCH] feat(debug): Exposed the internal Logger interface and its factory function --- src/api.ts | 6 +++--- src/debug.ts | 2 +- src/index.ts | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/api.ts b/src/api.ts index 3031b95..1dc969d 100644 --- a/src/api.ts +++ b/src/api.ts @@ -8,7 +8,7 @@ import { normalizeUri } from 'jsonref'; import { Schema, DynamicSchema } from 'jsonpolice'; import { Router, RouterOptions, RequestHandler, Request, Response, NextFunction } from 'express'; import { Eredita } from 'eredita'; -import debug, { Logger } from './debug'; +import { createLogger, Logger } from './debug'; import { RESTError } from './error'; import { SchemaRegistry } from './schema'; import { Swagger } from './swagger'; @@ -187,7 +187,7 @@ export class API implements Swagger { externalDocs?: Swagger.ExternalDocs; constructor(info?:Swagger, options?:APIOptions) { - this[__logger] = debug(this.getDebugLabel()); + this[__logger] = createLogger(this.getDebugLabel()); Object.assign(this, (new Eredita(info || {}, new Eredita(_.cloneDeep(__default_swagger)))).mergePath()); delete this.paths; delete this.tags; @@ -307,7 +307,7 @@ export class API implements Swagger { r.use((_req: Request, res: Response, next: NextFunction) => { let req: APIRequest = _req as APIRequest; if (!req.logger) { - req.logger = debug(this.getDebugLabel(), this.getDebugContext()); + req.logger = createLogger(this.getDebugLabel(), this.getDebugContext()); } next(); }); diff --git a/src/debug.ts b/src/debug.ts index ce0351d..41966e5 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -8,7 +8,7 @@ export interface Logger { debug: debug.IDebugger; } -export default function(label: string, context?: string): Logger { +export function createLogger(label: string, context?: string): Logger { let d = context ? function(label:string): debug.IDebugger { let origDebugger:debug.IDebugger = debug(label); let wrappedDebugger:debug.IDebugger = function(formatter: string, ...args: any[]) { diff --git a/src/index.ts b/src/index.ts index 95116b8..ec59074 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export * from './error'; +export * from './debug'; export * from './scopes'; export * from './schema'; export * from './api';