Skip to content

Commit 1666717

Browse files
committed
feat(debug): Exposed the internal Logger interface and its factory function
1 parent e37608d commit 1666717

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { normalizeUri } from 'jsonref';
88
import { Schema, DynamicSchema } from 'jsonpolice';
99
import { Router, RouterOptions, RequestHandler, Request, Response, NextFunction } from 'express';
1010
import { Eredita } from 'eredita';
11-
import debug, { Logger } from './debug';
11+
import { createLogger, Logger } from './debug';
1212
import { RESTError } from './error';
1313
import { SchemaRegistry } from './schema';
1414
import { Swagger } from './swagger';
@@ -187,7 +187,7 @@ export class API implements Swagger {
187187
externalDocs?: Swagger.ExternalDocs;
188188

189189
constructor(info?:Swagger, options?:APIOptions) {
190-
this[__logger] = debug(this.getDebugLabel());
190+
this[__logger] = createLogger(this.getDebugLabel());
191191
Object.assign(this, (new Eredita(info || {}, new Eredita(_.cloneDeep(__default_swagger)))).mergePath());
192192
delete this.paths;
193193
delete this.tags;
@@ -307,7 +307,7 @@ export class API implements Swagger {
307307
r.use((_req: Request, res: Response, next: NextFunction) => {
308308
let req: APIRequest = _req as APIRequest;
309309
if (!req.logger) {
310-
req.logger = debug(this.getDebugLabel(), this.getDebugContext());
310+
req.logger = createLogger(this.getDebugLabel(), this.getDebugContext());
311311
}
312312
next();
313313
});

src/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface Logger {
88
debug: debug.IDebugger;
99
}
1010

11-
export default function(label: string, context?: string): Logger {
11+
export function createLogger(label: string, context?: string): Logger {
1212
let d = context ? function(label:string): debug.IDebugger {
1313
let origDebugger:debug.IDebugger = debug(label);
1414
let wrappedDebugger:debug.IDebugger = <debug.IDebugger>function(formatter: string, ...args: any[]) {

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './error';
2+
export * from './debug';
23
export * from './scopes';
34
export * from './schema';
45
export * from './api';

0 commit comments

Comments
 (0)