Skip to content

fix: Add logger config #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions core/ClientBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -46,6 +47,7 @@ export class ClientBuilder<T> {
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) {
Expand Down Expand Up @@ -85,6 +87,11 @@ export class ClientBuilder<T> {
return this;
}

public withLogger(loggerOptions: LoggerOptions): ClientBuilder<T> {
this.loggerOptions = loggerOptions;
return this;
}

public build(): T {
const axiosOptions: ClientOptions = {
disableSslVerification: true
Expand All @@ -101,6 +108,14 @@ export class ClientBuilder<T> {
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();
}
Expand Down
5 changes: 5 additions & 0 deletions core/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down