diff --git a/core/ClientBuilder.ts b/core/ClientBuilder.ts index 14420091c..429d9d774 100644 --- a/core/ClientBuilder.ts +++ b/core/ClientBuilder.ts @@ -27,6 +27,7 @@ import { GlobalCredentials } from "./auth/GlobalCredentials"; import { SdkException } from "./exception/SdkException"; import { Region } from "./region/region"; import { UserOptions } from "./UserOptions"; +import { LoggerOptions } from "./logger"; import * as path from "path"; interface CredParams { @@ -46,6 +47,7 @@ export class ClientBuilder { private envParams: CredParams = process.env; private region?: Region; private userOptions?: UserOptions; + private loggerOptions?: LoggerOptions; private credentials: { [key: string]: ICredential } = {}; public constructor(init: (hcClient: HcClient) => T, credentialType?: string) { @@ -85,6 +87,11 @@ export class ClientBuilder { return this; } + public withLogger(loggerOptions: LoggerOptions): ClientBuilder { + this.loggerOptions = loggerOptions; + return this; + } + public build(): T { const axiosOptions: ClientOptions = { disableSslVerification: true @@ -101,6 +108,14 @@ export class ClientBuilder { axiosOptions.axiosRequestConfig = this.userOptions.axiosRequestConfig; } + if (this.loggerOptions?.logger) { + axiosOptions.logger = this.loggerOptions.logger; + } + + if (this.loggerOptions?.logLevel) { + axiosOptions.logLevel = this.loggerOptions.logLevel; + } + if (!this.credential) { this.credential = this.getCredentialFromEnvironment(); } diff --git a/core/logger/index.ts b/core/logger/index.ts index 515079a6c..aab260947 100644 --- a/core/logger/index.ts +++ b/core/logger/index.ts @@ -38,6 +38,11 @@ export interface Logger { setName(name: string): void; } +export interface LoggerOptions { + logger?: Logger; + logLevel?: LogLevel; +} + export class LoggerUtils { /** Map of severity as comparable numbers for each log level */