@openfn/logger
Advanced tools
Comparing version 0.0.19 to 0.0.20
# @openfn/logger | ||
## 0.0.20 | ||
### Patch Changes | ||
- 649ca43: In JSON mode, do not stringify emitted messages. | ||
Better handling of error objects | ||
## 0.0.19 | ||
@@ -4,0 +11,0 @@ |
// src/logger.ts | ||
import c from "chalk"; | ||
import iconfirm from "@inquirer/confirm"; | ||
import stringify2 from "fast-safe-stringify"; | ||
@@ -54,5 +53,25 @@ // src/symbols.ts | ||
}; | ||
var isError = (obj) => { | ||
if (obj instanceof Error) { | ||
return true; | ||
} | ||
let o = obj; | ||
while (o && o.constructor) { | ||
if (o.constructor.name === "Error") { | ||
return true; | ||
} | ||
o = o.prototype?.constructor; | ||
} | ||
return false; | ||
}; | ||
var sanitize = (item, options = {}) => { | ||
const maybeStringify = (o) => options.stringify === false ? o : stringify(o, void 0, 2); | ||
if (item instanceof Error) { | ||
if (isError(item)) { | ||
if (options.serializeErrors) { | ||
return { | ||
name: item.name, | ||
message: item.message || item.toString() | ||
// TODO stack? Tricky | ||
}; | ||
} | ||
return item; | ||
@@ -119,4 +138,4 @@ } | ||
// src/options.ts | ||
var defaultEmitter = { | ||
// src/util/default-emitter.ts | ||
var default_emitter_default = { | ||
...console, | ||
@@ -129,9 +148,22 @@ // Direct error and warn logs to stdout, so that they appear in sequence | ||
}; | ||
// src/util/json-emitter.ts | ||
import stringify2 from "fast-safe-stringify"; | ||
var jsonEmitter = { | ||
...console | ||
}; | ||
["log", "info", "success", "always", "debug", "warn", "error"].forEach((fn) => { | ||
jsonEmitter[fn] = (...args) => { | ||
const stringified = args.map((value) => stringify2(value)); | ||
console.log(...stringified); | ||
}; | ||
}); | ||
var json_emitter_default = jsonEmitter; | ||
// src/options.ts | ||
var defaults = { | ||
level: "default", | ||
// TODO support an array of emitters here | ||
logger: defaultEmitter, | ||
// I guess? | ||
hideNamespace: false, | ||
hideIcons: false, | ||
logger: default_emitter_default, | ||
// Not implemented | ||
@@ -149,2 +181,5 @@ wrap: false, | ||
...defaults, | ||
// If logging to json, and no emitter is provided, | ||
// use this emitter which will serialise the output to JSON | ||
logger: opts.json ? json_emitter_default : default_emitter_default, | ||
...opts | ||
@@ -209,3 +244,4 @@ }; | ||
stringify: false, | ||
policy: options.sanitize | ||
policy: options.sanitize, | ||
serializeErrors: true | ||
}) | ||
@@ -222,3 +258,3 @@ ); | ||
}; | ||
emitter[level](stringify2(output)); | ||
emitter[level](output); | ||
}; | ||
@@ -263,3 +299,3 @@ const logString = (name2, level, ...args) => { | ||
if (opts.json) { | ||
emitter.info(JSON.stringify({ message: args })); | ||
emitter.info({ message: args }); | ||
} else { | ||
@@ -266,0 +302,0 @@ emitter.info(...args); |
{ | ||
"name": "@openfn/logger", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "Cross-package logging utility", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.js", |
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
18653
503