@@ -6,12 +6,20 @@ import * as winston from 'winston';
66import * as namings from './namings' ;
77import { ExpressContextType , ISecurityContextFactory } from './descriptions' ;
88
9+ export interface JsRestfulRegistryConfig {
10+ logger ?: winston . Winston | winston . LoggerInstance ;
11+ }
12+
913export class JsRestfulRegistry {
1014
1115 private registeredServices :any [ ] = [ ] ;
1216 private securityContextFactory :ISecurityContextFactory = null ;
1317
14- constructor ( private app :express . Application ) { }
18+ constructor ( private app :express . Application , private config : JsRestfulRegistryConfig = { } ) {
19+ if ( ! config . logger ) {
20+ config . logger = winston ;
21+ }
22+ }
1523
1624 registerSecurityContextFactory ( factory :ISecurityContextFactory ) {
1725 this . securityContextFactory = factory ;
@@ -35,7 +43,7 @@ export class JsRestfulRegistry {
3543 }
3644 }
3745
38- winston . log ( ' info' , `${ service . constructor . name } will be registered` ) ;
46+ this . config . logger . info ( `${ service . constructor . name } will be registered` ) ;
3947 // store the service at the app
4048 this . registeredServices . push ( service . constructor . name ) ;
4149
@@ -48,7 +56,7 @@ export class JsRestfulRegistry {
4856
4957 let path = method . path ? method . path : '/' ;
5058
51- winston . log ( ' info' , `register method ${ method . methodName } for path ${ path } ` ) ;
59+ this . config . logger . info ( `register method ${ method . methodName } for path ${ path } ` ) ;
5260
5361 router [ httpMethodName ] ( path , ( req : express . Request , res : express . Response , next : express . NextFunction ) => {
5462 try {
@@ -106,7 +114,7 @@ export class JsRestfulRegistry {
106114
107115 let basePath = pathUtil . getPathFromString ( descriptions . basePath ) ;
108116 this . app . use ( basePath , router ) ;
109- winston . log ( ' info' , `${ service . constructor . name } published at ${ basePath } ` ) ;
117+ this . config . logger . info ( `${ service . constructor . name } published at ${ basePath } ` ) ;
110118 }
111119
112120 collectAndConvertArgs ( req :express . Request , res : express . Response , next :express . NextFunction , service :Object , method :MethodDescription ) : any [ ] {
0 commit comments