Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/shy-bikes-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@human-protocol/logger": minor
---

fix: logger name in child loggers
feat: logger name is public readonly
7 changes: 5 additions & 2 deletions packages/libs/logger/src/abstract-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function serializeError(error: ErrorLike) {

abstract class LoggerWrapper implements Logger {
protected readonly bindings: LogMeta;
private readonly name?: string;
readonly name?: string;

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

return this.createChild(bindings);
return this.createChild({
name: this.name,
...bindings,
});
}

protected abstract createChild(bindings: LogMeta): Logger;
Expand Down
1 change: 1 addition & 0 deletions packages/libs/logger/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type LogFn = {
export type ChildBindings = { name?: string } & LogMeta;

export interface Logger {
name?: string;
debug: LogFn;
info: LogFn;
warn: LogFn;
Expand Down
Loading