Skip to content

Commit

Permalink
fix: interface ILogLayer corrections (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
theogravity committed May 28, 2024
1 parent bf50089 commit 1d67e1f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
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

0 comments on commit 1d67e1f

Please sign in to comment.