@openfn/logger
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -40,2 +40,4 @@ type SanitizePolicies = 'remove' | 'obfuscate' | 'summarize' | 'none'; | ||
always(...args: any[]): void; | ||
proxy(obj: Partial<JSONLog>): void; | ||
proxy(name: string, level: string, message: any[]): void; | ||
print(...args: any[]): void; | ||
@@ -70,2 +72,2 @@ confirm(message: string, force?: boolean): Promise<boolean>; | ||
export { JSONLog, LogLevel, LogOptions, Logger, StringLog, mockLogger as createMockLogger, export_default as default, defaultLogger, _default$1 as isValidLogLevel, _default as printDuration }; | ||
export { JSONLog, LogLevel, LogOptions, Logger, SanitizePolicies, StringLog, mockLogger as createMockLogger, export_default as default, defaultLogger, _default$1 as isValidLogLevel, _default as printDuration }; |
@@ -116,2 +116,5 @@ // src/logger.ts | ||
...console, | ||
// Direct error and warn logs to stdout, so that they appear in sequence | ||
error: (...args) => console.log(...args), | ||
warn: (...args) => console.log(...args), | ||
success: (...args) => console.log(...args), | ||
@@ -185,12 +188,12 @@ always: (...args) => console.log(...args) | ||
const emitter = opts.logger; | ||
const log = (level, ...args) => { | ||
const log = (name2, level, ...args) => { | ||
if (priority[level] >= minLevel) { | ||
if (options.json) { | ||
logJSON(level, ...args); | ||
logJSON(name2, level, ...args); | ||
} else { | ||
logString(level, ...args); | ||
logString(name2, level, ...args); | ||
} | ||
} | ||
}; | ||
const logJSON = (level, ...args) => { | ||
const logJSON = (name2, level, ...args) => { | ||
const message = args.map( | ||
@@ -207,3 +210,3 @@ (o) => sanitize_default(o, { | ||
level, | ||
name, | ||
name: name2, | ||
message, | ||
@@ -215,3 +218,3 @@ time: Date.now() | ||
}; | ||
const logString = (level, ...args) => { | ||
const logString = (name2, level, ...args) => { | ||
if (emitter.hasOwnProperty(level)) { | ||
@@ -230,4 +233,4 @@ const cleanedArgs = args.map( | ||
const output = []; | ||
if (name && !opts.hideNamespace) { | ||
output.push(c.blue(`[${name}]`)); | ||
if (name2 && !opts.hideNamespace) { | ||
output.push(c.blue(`[${name2}]`)); | ||
} | ||
@@ -241,2 +244,13 @@ if (!opts.hideIcons) { | ||
}; | ||
const proxy = function(...args) { | ||
let j; | ||
if (args.length === 3) { | ||
const [name2, level, message] = args; | ||
j = { name: name2, level, message }; | ||
} else { | ||
j = args[0]; | ||
} | ||
j = j; | ||
log(j.name, j.level, ...j.message); | ||
}; | ||
const print = (...args) => { | ||
@@ -266,3 +280,3 @@ if (opts.level !== NONE) { | ||
}; | ||
const wrap = (level) => (...args) => log(level, ...args); | ||
const wrap = (level) => (...args) => log(name, level, ...args); | ||
const logger = { | ||
@@ -279,2 +293,3 @@ info: wrap(INFO), | ||
print, | ||
proxy, | ||
// possible convenience APIs | ||
@@ -281,0 +296,0 @@ force: () => { |
{ | ||
"name": "@openfn/logger", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "Cross-package logging utility", | ||
@@ -37,3 +37,4 @@ "module": "dist/index.js", | ||
"dist", | ||
"README.md" | ||
"README.md", | ||
"CHANGELOG.md" | ||
], | ||
@@ -40,0 +41,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17239
5
464