Skip to content

Commit

Permalink
feat(logger): add TRACE log level
Browse files Browse the repository at this point in the history
  • Loading branch information
maksadbek committed Nov 25, 2024
1 parent ce4baed commit 61c515a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/RequestExecutor/HttpRequestExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ export class HttpRequestExecutor implements RequestExecutor {

const { res, body } = await this.request(options);

logger.trace(
'received following response for request %j: headers: %j body: %s',
{
url: options.url,
protocol: this.protocol,
method: options.method
},
{
statusCode: res.statusCode,
headers: res.headers
},
body.slice(0, 500).concat(body.length > 500 ? '...' : '')
);

return new Response({
body,
protocol: this.protocol,
Expand Down
12 changes: 11 additions & 1 deletion src/Utils/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export enum LogLevel {
ERROR,
WARN,
NOTICE,
VERBOSE
VERBOSE,
TRACE
}

export class Logger {
Expand Down Expand Up @@ -79,6 +80,14 @@ export class Logger {
this.write(message, LogLevel.VERBOSE, ...args);
}

public trace(message: string, ...args: any[]): void {
if (this.logLevel < LogLevel.TRACE) {
return;
}

this.write(message, LogLevel.TRACE, ...args);
}

private write(message: string, level: LogLevel, ...args: any[]): void {
const logMessage = `${this.formatHeader(level)} - ${message}`;

Expand All @@ -105,6 +114,7 @@ export class Logger {
case LogLevel.NOTICE:
return chalk.green(header);
case LogLevel.VERBOSE:
case LogLevel.TRACE:
return chalk.cyan(header);
}
}
Expand Down

0 comments on commit 61c515a

Please sign in to comment.