@notesnook/logger
Advanced tools
+4
-3
| import { ILogReporter, LoggerConfig } from "./types"; | ||
| type LogLevelFunc = (message: string, extras?: Record<string, unknown>) => void; | ||
| type ErrorLogLevelFunc = (error: Error, fallbackMessage?: string, extras?: Record<string, unknown>) => void; | ||
| type ErrorLogLevelFunc = (error: Error | unknown, fallbackMessage?: string, extras?: Record<string, unknown>) => void; | ||
| export interface ILogger { | ||
@@ -18,6 +18,6 @@ fatal: ErrorLogLevelFunc; | ||
| scope(scope: string): Logger; | ||
| fatal: (error: Error, fallbackMessage?: string | undefined, extras?: Record<string, unknown> | undefined) => void; | ||
| fatal: (error: unknown, fallbackMessage?: string | undefined, extras?: Record<string, unknown> | undefined) => void; | ||
| warn: (message: string, extras?: Record<string, unknown> | undefined) => void; | ||
| debug: (message: string, extras?: Record<string, unknown> | undefined) => void; | ||
| error: (error: Error, fallbackMessage?: string | undefined, extras?: Record<string, unknown> | undefined) => void; | ||
| error: (error: unknown, fallbackMessage?: string | undefined, extras?: Record<string, unknown> | undefined) => void; | ||
| info: (message: string, extras?: Record<string, unknown> | undefined) => void; | ||
@@ -36,2 +36,3 @@ log: (message: string, extras?: Record<string, unknown> | undefined) => void; | ||
| scope(): this; | ||
| replaceWith(logger: ILogger): void; | ||
| } | ||
@@ -38,0 +39,0 @@ export * from "./types"; |
+8
-3
@@ -58,2 +58,5 @@ /* | ||
| } | ||
| replaceWith(logger) { | ||
| Object.assign(this, logger); | ||
| } | ||
| } | ||
@@ -81,9 +84,11 @@ export * from "./types"; | ||
| level, | ||
| message: error.stack | ||
| message: error instanceof Error && error.stack | ||
| ? error.stack.trim() | ||
| : fallbackMessage | ||
| ? fallbackMessage | ||
| : "An error occurred.", | ||
| : "An unknown error occurred.", | ||
| timestamp: now, | ||
| extras, | ||
| extras: error instanceof Error | ||
| ? Object.assign(Object.assign({}, extras), { fallbackMessage }) : error | ||
| ? Object.assign(Object.assign({}, extras), { error }) : extras, | ||
| scope: config.scope, | ||
@@ -90,0 +95,0 @@ elapsed: now - config.lastTime |
+3
-3
| { | ||
| "name": "@notesnook/logger", | ||
| "version": "1.0.3", | ||
| "version": "2.0.0", | ||
| "description": "A really simple logger with a pluggable interface.", | ||
| "main": "dist/index.js", | ||
| "scripts": { | ||
| "pub": "tsc && np", | ||
| "build": "tsc" | ||
| "build": "tsc", | ||
| "prepublishOnly": "npm run build" | ||
| }, | ||
@@ -10,0 +10,0 @@ "repository": { |
10530
3.57%270
2.27%