@@ -18,6 +18,7 @@ import IServer from "../../../interfaces/Server/IServer";
18
18
import * as NodeJSUtils from "../../../utils/NodeJS.util" ;
19
19
import { DaprClient } from "../../.." ;
20
20
import { createHttpTerminator } from 'http-terminator' ;
21
+ import { Logger } from "../../../logger/Logger" ;
21
22
22
23
// eslint-disable-next-line
23
24
export interface IServerImplType extends HTTPServerImpl { }
@@ -33,11 +34,16 @@ export default class HTTPServer implements IServer {
33
34
serverImpl : IServerImplType ;
34
35
daprSidecarPollingDelayMs = 1000 ;
35
36
client : DaprClient ;
37
+ private readonly logger : Logger ;
36
38
37
- constructor ( client : DaprClient ) {
39
+ private readonly LOG_COMPONENT : string = "HTTPServer" ;
40
+ private readonly LOG_AREA : string = "HTTPServer" ;
41
+
42
+ constructor ( client : DaprClient , logger : Logger ) {
38
43
this . serverHost = "" ;
39
44
this . serverPort = "" ;
40
45
this . client = client ;
46
+ this . logger = logger ;
41
47
42
48
this . isInitialized = false ;
43
49
@@ -103,14 +109,14 @@ export default class HTTPServer implements IServer {
103
109
104
110
// Initialize Server Listener
105
111
await this . server . start ( parseInt ( port , 10 ) ) ;
106
- console . log ( `[Dapr-JS] Listening on ${ port } `) ;
112
+ this . logger . info ( this . LOG_COMPONENT , this . LOG_AREA , ` Listening on ${ port } `) ;
107
113
this . serverAddress = `http://${ host } :${ port } ` ;
108
114
109
115
// Add PubSub Routes
110
- console . log ( `[Dapr API][PubSub] Registering ${ this . serverImpl . pubSubSubscriptionRoutes . length } PubSub Subscriptions`) ;
116
+ this . logger . info ( this . LOG_COMPONENT , this . LOG_AREA , ` Registering ${ this . serverImpl . pubSubSubscriptionRoutes . length } PubSub Subscriptions`) ;
111
117
this . server . get ( '/dapr/subscribe' , ( req , res ) => {
112
118
res . send ( this . serverImpl . pubSubSubscriptionRoutes ) ;
113
- console . log ( `[Dapr API][PubSub] Registered ${ this . serverImpl . pubSubSubscriptionRoutes . length } PubSub Subscriptions`) ;
119
+ this . logger . info ( this . LOG_COMPONENT , this . LOG_AREA , ` Registered ${ this . serverImpl . pubSubSubscriptionRoutes . length } PubSub Subscriptions`) ;
114
120
} ) ;
115
121
116
122
// We need to call the Singleton to start listening on the port, else Dapr will not pick it up correctly
@@ -120,9 +126,9 @@ export default class HTTPServer implements IServer {
120
126
let isHealthyRetryCount = 0 ;
121
127
const isHealthyMaxRetryCount = 60 ; // 1s startup delay and we try max for 60s
122
128
123
- console . log ( `[Dapr-JS] Letting Dapr pick-up the server (Maximum 60s wait time)`) ;
129
+ this . logger . info ( this . LOG_COMPONENT , this . LOG_AREA , ` Letting Dapr pick-up the server (Maximum 60s wait time)`) ;
124
130
while ( ! isHealthy ) {
125
- console . log ( `[Dapr-JS] - Waiting till Dapr Started (#${ isHealthyRetryCount } )`) ;
131
+ this . logger . verbose ( this . LOG_COMPONENT , this . LOG_AREA , ` Waiting for Dapr to start, retry counter is (#${ isHealthyRetryCount } )`) ;
126
132
await NodeJSUtils . sleep ( this . daprSidecarPollingDelayMs ) ;
127
133
isHealthy = await this . client . health . isHealthy ( ) ;
128
134
isHealthyRetryCount ++ ;
@@ -133,7 +139,7 @@ export default class HTTPServer implements IServer {
133
139
}
134
140
135
141
// We are initialized
136
- console . log ( `[Dapr-JS] Server Started` ) ;
142
+ this . logger . info ( this . LOG_COMPONENT , this . LOG_AREA , " Server Started" ) ;
137
143
this . isInitialized = true ;
138
144
}
139
145
0 commit comments