Skip to content
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

feat: add silent() method #35

Merged
merged 1 commit into from
Aug 12, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/friendly-gifts-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"loglayer": minor
---

Add silent() method.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ const childLog = parentLog.child()
- `LogLayer#debug(...messages: MessageDataType[]): void`
- `LogLayer#trace(...messages: MessageDataType[]): void`
- `LogLayer#fatal(...messages: MessageDataType[]): void`
- `LogLayer#silent(...messages: MessageDataType[]): void`

`type MessageDataType = string | number | null | undefined`

Expand All @@ -623,6 +624,7 @@ to the following levels in that situation:

* `trace` -> `debug`
* `fatal` -> `error`
* `silent` -> (no-op)

*Your logging library may or may not support passing multiple parameters. See your logging library's
documentation for more details.*
Expand Down
8 changes: 8 additions & 0 deletions src/LogBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ export class LogBuilder<ExternalLogger extends LoggerLibrary = LoggerLibrary, Er
this.formatLog(LogLevel.fatal, messages);
}

/**
* No-op method that does nothing.
*/
silent(...messages: MessageDataType[]) {
this.structuredLogger._formatMessage(messages);
this.formatLog(LogLevel.silent, messages);
}

/**
* All logging inputs are dropped and stops sending logs to the logging library.
*/
Expand Down
13 changes: 13 additions & 0 deletions src/LogLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ export class LogLayer<ExternalLogger extends LoggerLibrary = LoggerLibrary, Erro
this._formatLog({ logLevel: LogLevel.fatal, params: messages });
}

/**
* No-op method that does nothing.
*/
silent(...messages: MessageDataType[]) {
this._formatMessage(messages);
this._formatLog({ logLevel: LogLevel.silent, params: messages });
}

/**
* All logging inputs are dropped and stops sending logs to the logging library.
*/
Expand Down Expand Up @@ -549,6 +557,11 @@ export class LogLayer<ExternalLogger extends LoggerLibrary = LoggerLibrary, Erro
this.loggerInstance.error(...params);
}
break;
case LogLevel.silent:
if (this.loggerInstance.silent) {
this.loggerInstance.silent(...params);
}
break;
default:
if (consoleDebug) {
console.log(...params);
Expand Down
2 changes: 2 additions & 0 deletions src/MockLogBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class MockLogBuilder implements ILogBuilder {

fatal(...messages: MessageDataType[]): void {}

silent(...messages: MessageDataType[]): void {}

enableLogging() {
return this;
}
Expand Down
1 change: 1 addition & 0 deletions src/MockLogLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class MockLogLayer<ErrorType = Error> implements ILogLayer<any, ErrorType
debug(...messages: MessageDataType[]): void {}
trace(...messages: MessageDataType[]): void {}
fatal(...messages: MessageDataType[]): void {}
silent(...messages: MessageDataType[]): void {}

getLoggerInstance() {}

Expand Down
1 change: 1 addition & 0 deletions src/types/common.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum LogLevel {
debug = "debug",
trace = "trace",
fatal = "fatal",
silent = "silent",
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface LoggerLibrary {
trace?: (...data: any[]) => void;
debug(...data: any[]): void;
fatal?: (...data: any[]) => void;
silent?: (...data: any[]) => void;
}

export interface ILogBuilder {
Expand Down Expand Up @@ -60,6 +61,11 @@ export interface ILogBuilder {
* the first parameter would be used.
*/
fatal(...messages: MessageDataType[]): void;

/**
* No-op method that does nothing.
*/
silent(): void;
}

export interface ILogLayer<ExternalLogger extends LoggerLibrary = LoggerLibrary, ErrorType = ErrorDataType>
Expand Down
Loading