@open-draft/logger
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -30,3 +30,3 @@ type ColorFunction = (text: string) => void; | ||
level: LogLevel; | ||
message: string; | ||
message: any; | ||
} | ||
@@ -43,3 +43,3 @@ declare class Logger { | ||
*/ | ||
debug(message: string, ...positionals: Array<unknown>): void; | ||
debug(message: any, ...positionals: Array<unknown>): void; | ||
/** | ||
@@ -50,3 +50,3 @@ * Print an info message. | ||
*/ | ||
info(message: string, ...positionals: Array<unknown>): (message: string, ...positionals: Array<unknown>) => void; | ||
info(message: any, ...positionals: Array<unknown>): (message: any, ...positionals: Array<unknown>) => void; | ||
/** | ||
@@ -57,3 +57,3 @@ * Print a success message. | ||
*/ | ||
success(message: string, ...positionals: Array<unknown>): void; | ||
success(message: any, ...positionals: Array<unknown>): void; | ||
/** | ||
@@ -64,3 +64,3 @@ * Print a warning. | ||
*/ | ||
warning(message: string, ...positionals: Array<unknown>): void; | ||
warning(message: any, ...positionals: Array<unknown>): void; | ||
/** | ||
@@ -71,3 +71,3 @@ * Print an error message. | ||
*/ | ||
error(message: string, ...positionals: Array<unknown>): void; | ||
error(message: any, ...positionals: Array<unknown>): void; | ||
/** | ||
@@ -74,0 +74,0 @@ * Execute the given callback only when the logging is enabled. |
@@ -212,4 +212,4 @@ var __defProp = Object.defineProperty; | ||
write( | ||
[colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(message).join(" "), | ||
...positionals | ||
[colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(serializeInput(message)).join(" "), | ||
...positionals.map(serializeInput) | ||
); | ||
@@ -282,1 +282,16 @@ } | ||
} | ||
function serializeInput(message) { | ||
if (typeof message === "undefined") { | ||
return "undefined"; | ||
} | ||
if (message === null) { | ||
return "null"; | ||
} | ||
if (typeof message === "string") { | ||
return message; | ||
} | ||
if (typeof message === "object") { | ||
return JSON.stringify(message); | ||
} | ||
return message.toString(); | ||
} |
@@ -30,3 +30,3 @@ type ColorFunction = (text: string) => void; | ||
level: LogLevel; | ||
message: string; | ||
message: any; | ||
} | ||
@@ -43,3 +43,3 @@ declare class Logger { | ||
*/ | ||
debug(message: string, ...positionals: Array<unknown>): void; | ||
debug(message: any, ...positionals: Array<unknown>): void; | ||
/** | ||
@@ -50,3 +50,3 @@ * Print an info message. | ||
*/ | ||
info(message: string, ...positionals: Array<unknown>): (message: string, ...positionals: Array<unknown>) => void; | ||
info(message: any, ...positionals: Array<unknown>): (message: any, ...positionals: Array<unknown>) => void; | ||
/** | ||
@@ -57,3 +57,3 @@ * Print a success message. | ||
*/ | ||
success(message: string, ...positionals: Array<unknown>): void; | ||
success(message: any, ...positionals: Array<unknown>): void; | ||
/** | ||
@@ -64,3 +64,3 @@ * Print a warning. | ||
*/ | ||
warning(message: string, ...positionals: Array<unknown>): void; | ||
warning(message: any, ...positionals: Array<unknown>): void; | ||
/** | ||
@@ -71,3 +71,3 @@ * Print an error message. | ||
*/ | ||
error(message: string, ...positionals: Array<unknown>): void; | ||
error(message: any, ...positionals: Array<unknown>): void; | ||
/** | ||
@@ -74,0 +74,0 @@ * Execute the given callback only when the logging is enabled. |
@@ -212,4 +212,4 @@ var __defProp = Object.defineProperty; | ||
write( | ||
[colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(message).join(" "), | ||
...positionals | ||
[colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(serializeInput(message)).join(" "), | ||
...positionals.map(serializeInput) | ||
); | ||
@@ -282,2 +282,17 @@ } | ||
} | ||
function serializeInput(message) { | ||
if (typeof message === "undefined") { | ||
return "undefined"; | ||
} | ||
if (message === null) { | ||
return "null"; | ||
} | ||
if (typeof message === "string") { | ||
return message; | ||
} | ||
if (typeof message === "object") { | ||
return JSON.stringify(message); | ||
} | ||
return message.toString(); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -284,0 +299,0 @@ 0 && (module.exports = { |
{ | ||
"name": "@open-draft/logger", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Environment-agnostic, ESM-friendly logger for simple needs.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/node/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
41529
1304