Skip to content

Commit 7ded32b

Browse files
authored
[Logger] fix: logger name in child loggers (#3733)
1 parent 6a01975 commit 7ded32b

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

.changeset/shy-bikes-roll.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@human-protocol/logger": minor
3+
---
4+
5+
fix: logger name in child loggers
6+
feat: logger name is public readonly

packages/libs/logger/src/abstract-logger.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function serializeError(error: ErrorLike) {
5555

5656
abstract class LoggerWrapper implements Logger {
5757
protected readonly bindings: LogMeta;
58-
private readonly name?: string;
58+
readonly name?: string;
5959

6060
constructor(bindings: LogMeta = {}) {
6161
if (!isPlainObject(bindings)) {
@@ -92,7 +92,10 @@ abstract class LoggerWrapper implements Logger {
9292
throw new Error('Log bindings required for child logger');
9393
}
9494

95-
return this.createChild(bindings);
95+
return this.createChild({
96+
name: this.name,
97+
...bindings,
98+
});
9699
}
97100

98101
protected abstract createChild(bindings: LogMeta): Logger;

packages/libs/logger/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type LogFn = {
2323
export type ChildBindings = { name?: string } & LogMeta;
2424

2525
export interface Logger {
26+
name?: string;
2627
debug: LogFn;
2728
info: LogFn;
2829
warn: LogFn;

0 commit comments

Comments
 (0)