Skip to content

Commit

Permalink
feat(debug): Exposed the internal Logger interface and its factory fu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
0xfede committed May 9, 2017
1 parent e37608d commit 1666717
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <debug.IDebugger>function(formatter: string, ...args: any[]) {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './error';
export * from './debug';
export * from './scopes';
export * from './schema';
export * from './api';
Expand Down

0 comments on commit 1666717

Please sign in to comment.