Skip to content

Commit

Permalink
feat(logging): minor changes in console logger
Browse files Browse the repository at this point in the history
  • Loading branch information
kedrzu committed Sep 13, 2023
1 parent 242077c commit 90234fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/logging/src/ConsoleLogger.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { defineFactory } from '@nzyme/ioc';

import { Logger, LoggerArgs } from './Logger.js';
import { Logger, LoggerArgs, LoggerErrorArgs } from './Logger.js';
import { perf } from './perf.js';

export class ConsoleLogger implements Logger {
constructor(private readonly name: string = '') {}
constructor(public readonly name: string = '') {}

public error(error: unknown, args?: LoggerArgs): void;
public error(message: string, args?: LoggerArgs): void;
public error(message: string, args?: LoggerErrorArgs): void;
public error(message: string | unknown, args?: LoggerArgs): void {
if (typeof message === 'string') {
console.error(this.format(message), args);
Expand Down Expand Up @@ -62,7 +62,7 @@ export class ConsoleLogger implements Logger {
this.info(formatted);
}

private format(message: string) {
protected format(message: string) {
return this.name ? `${this.name}: ${message}` : message;
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/logging/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ export type LoggerArgs = {
[key: string]: unknown;
};

export type LoggerErrorArgs = {
error?: unknown;
[key: string]: unknown;
};

export interface Logger {
error(error: unknown, args?: LoggerArgs): void;
error(message: string, args?: LoggerArgs): void;
error(message: string, args?: LoggerErrorArgs): void;
warn(message: string, args?: LoggerArgs): void;
info(message: string, args?: LoggerArgs): void;
success(message: string, args?: LoggerArgs): void;
Expand Down

0 comments on commit 90234fa

Please sign in to comment.