Skip to content

Commit

Permalink
feat: add types for LightLogger compatible with console (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny authored Aug 5, 2024
1 parent 88a1e1a commit fad1b27
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
33 changes: 33 additions & 0 deletions src/core/LightLogger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Many libraries use a logger interface to log information about the processing.
* This logger is expected to be compatible not only with the one from the `pino` library but
* also with the default `console`.
* This means that the library can output logs by default to the console and the user can
* replace it with a custom logger that implements this interface.
*/
export interface LightLogger {
trace(obj: Record<string, unknown>, message: string): void;
trace(message: string): void;
trace(error: Error): void;
trace(value: unknown, message?: string): void;

debug(obj: Record<string, unknown>, message: string): void;
debug(message: string): void;
debug(error: Error): void;
debug(value: unknown, message?: string): void;

info(obj: Record<string, unknown>, message: string): void;
info(message: string): void;
info(error: Error): void;
info(value: unknown, message?: string): void;

warn(obj: Record<string, unknown>, message: string): void;
warn(message: string): void;
warn(error: Error): void;
warn(value: unknown, message?: string): void;

error(obj: Record<string, unknown>, message: string): void;
error(message: string): void;
error(error: Error): void;
error(value: unknown, message?: string): void;
}
32 changes: 4 additions & 28 deletions src/core/Logger.d.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
import { LightLogger } from './LightLogger';

/**
* Many libraries use a logger interface to log information about the processing
* Many libraries use a logger interface to log information about the processing.
* This logger is expected to be compatible with the one from the `pino` library
*/

export interface Logger {
export interface Logger extends LightLogger {
child(bindings?: Record<string, any>): Logger;

Check warning on line 8 in src/core/Logger.d.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected any. Specify a different type

trace(obj: Record<string, unknown>, message: string): void;
trace(message: string): void;
trace(error: Error): void;
trace(value: unknown, message?: string): void;

debug(obj: Record<string, unknown>, message: string): void;
debug(message: string): void;
debug(error: Error): void;
debug(value: unknown, message?: string): void;

info(obj: Record<string, unknown>, message: string): void;
info(message: string): void;
info(error: Error): void;
info(value: unknown, message?: string): void;

warn(obj: Record<string, unknown>, message: string): void;
warn(message: string): void;
warn(error: Error): void;
warn(value: unknown, message?: string): void;

error(obj: Record<string, unknown>, message: string): void;
error(message: string): void;
error(error: Error): void;
error(value: unknown, message?: string): void;

fatal(obj: Record<string, unknown>, message: string): void;
fatal(message: string): void;
fatal(error: Error): void;
Expand Down

0 comments on commit fad1b27

Please sign in to comment.