@@ -19,6 +19,7 @@ import https from "https";
1919import { DaprClientOptions } from "../../../types/DaprClientOptions" ;
2020import { Settings } from '../../../utils/Settings.util' ;
2121import { THTTPExecuteParams } from "../../../types/http/THTTPExecuteParams.type"
22+ import { Logger } from "../../../logger/Logger" ;
2223
2324export default class HTTPClient implements IClient {
2425 private isInitialized : boolean ;
@@ -28,6 +29,7 @@ export default class HTTPClient implements IClient {
2829 private readonly clientPort : string ;
2930 private readonly clientUrl : string ;
3031 private readonly options : DaprClientOptions ;
32+ private readonly logger : Logger ;
3133
3234 private readonly httpAgent ;
3335 private readonly httpsAgent ;
@@ -37,11 +39,12 @@ export default class HTTPClient implements IClient {
3739 , port = Settings . getDefaultHttpPort ( )
3840 , options : DaprClientOptions = {
3941 isKeepAlive : true
40- }
42+ } ,
4143 ) {
4244 this . clientHost = host ;
4345 this . clientPort = port ;
4446 this . options = options ;
47+ this . logger = new Logger ( "HTTPClient" , "HTTPClient" , this . options . logger ) ;
4548 this . isInitialized = false ;
4649
4750 if ( ! this . clientHost . startsWith ( 'http://' ) && ! this . clientHost . startsWith ( 'https://' ) ) {
@@ -138,7 +141,7 @@ export default class HTTPClient implements IClient {
138141 params . headers [ "Content-Type" ] = "text/plain" ;
139142 break ;
140143 default :
141- console . log ( `Unknown body type: ${ typeof params ?. body } , defaulting to "text/plain"` ) ;
144+ this . logger . warn ( `Unknown body type: ${ typeof params ?. body } , defaulting to "text/plain"` ) ;
142145 params . headers [ "Content-Type" ] = "text/plain" ;
143146 break ;
144147 }
@@ -153,7 +156,8 @@ export default class HTTPClient implements IClient {
153156 await this . start ( ) ;
154157 }
155158
156- // console.log(`${params.method} - ${urlFull} (${params.body})`);
159+ this . logger . debug ( `Fetching ${ params . method } ${ urlFull } with body: (${ params . body } )` ) ;
160+
157161 const res = await fetch ( urlFull , params ) ;
158162
159163 // Parse body
@@ -184,7 +188,7 @@ export default class HTTPClient implements IClient {
184188 }
185189 // All the others
186190 else {
187- console . log ( txtParsed ) ;
191+ this . logger . debug ( "Execute response text: %s" , txtParsed ) ;
188192 throw new Error ( JSON . stringify ( {
189193 error : "UNKNOWN" ,
190194 error_msg : `An unknown problem occured and we got the status ${ res . status } with response ${ JSON . stringify ( res ) } `
0 commit comments