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

fix: interface ILogLayer corrections #33

Merged
merged 1 commit into from
May 28, 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
9 changes: 9 additions & 0 deletions .changeset/bright-trees-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"loglayer": minor
---

Fix ILogLayer return types

`ILogLayer#withPrefix()` and `ILogLayer#withChild()` were of the incorrect return type.

Changed to `ILogLayer<ExternalLogger, ErrorType>`.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ The same log commands would now be formatted as:

### Child logger

`LogLayer#child()`
`LogLayer#child(): LogLayer`

You can create a child logger, which will copy the configuration you used for creating the parent, along with the existing context data and plugins.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/MockLogLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { MockLogBuilder } from "./MockLogBuilder";
import type { ErrorOnlyOpts, ILogBuilder, ILogLayer, LogLayerPlugin } from "./types";
import type { LogLevel, MessageDataType } from "./types/common.types";
import type { LogLevel, MessageDataType } from "./types";

export class MockLogLayer<ErrorType = Error> implements ILogLayer<any, ErrorType> {
info(...messages: MessageDataType[]): void {}
Expand All @@ -28,11 +28,11 @@ export class MockLogLayer<ErrorType = Error> implements ILogLayer<any, ErrorType
disablePlugin(id: string) {}

withPrefix(prefix: string) {
return new MockLogLayer();
return new MockLogLayer() as ILogLayer<any, ErrorType>;
}

withContext(context: Record<string, any>): ILogLayer<any, ErrorType> {
return this;
return this as ILogLayer<any, ErrorType>;
}

withError(error: ErrorType): ILogBuilder {
Expand All @@ -56,7 +56,7 @@ export class MockLogLayer<ErrorType = Error> implements ILogLayer<any, ErrorType
}

child() {
return new MockLogLayer();
return new MockLogLayer() as ILogLayer<any, ErrorType>;
}

muteContext() {
Expand Down
4 changes: 2 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface ILogLayer<ExternalLogger extends LoggerLibrary = LoggerLibrary,
/**
* Calls child() and sets the prefix to be included with every log message.
*/
withPrefix(string: string): ILogBuilder;
withPrefix(string: string): ILogLayer<ExternalLogger, ErrorType>;
/**
* Appends context data which will be included with
* every log entry.
Expand Down Expand Up @@ -106,7 +106,7 @@ export interface ILogLayer<ExternalLogger extends LoggerLibrary = LoggerLibrary,
*
* The copied context data is a *shallow copy*.
*/
child(): ILogBuilder;
child(): ILogLayer<ExternalLogger, ErrorType>;

/**
* Disables inclusion of context data in the print
Expand Down
Loading