@zudojs/logger 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -151,9 +151,14 @@ logger.info("login", { user: "alice", password: "hunter2" });
151
151
  // metadata: { user: "alice", password: "[REDACTED]" }
152
152
 
153
153
  createLogger({ redact: { keys: ["ssn"], replacement: "***" } });
154
- createLogger({ redact: { enabled: false } }); // opt out
154
+ createLogger({ redact: false }); // opt out
155
+ createLogger({ redact: { enabled: false } }); // same as redact: false
155
156
  ```
156
157
 
158
+ `redact` takes a boolean or an options object (`enabled`, `keys`, `pattern`,
159
+ `replacement`). `true` or omitting it keeps the default. Child loggers inherit
160
+ the parent's setting.
161
+
157
162
  ## Log injection
158
163
 
159
164
  Text-shaped formatters escape control characters (C0, DEL, C1 and
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Normalization of the `redact` logger option.
3
+ */
4
+ import type { LoggerRedactionOptions } from "../loggerEntry/loggerEntryHelpers/loggerEntryHelpers.sanitize.js";
5
+ /**
6
+ * Resolves the `redact` option into frozen redaction settings.
7
+ *
8
+ * `false` turns redaction off and `true` (or omitting it) keeps the default.
9
+ * An object is used as given. Spreading `false` into an object yields `{}`,
10
+ * which is the default, so a boolean must be mapped explicitly.
11
+ *
12
+ * @param redact - The `redact` value passed to `createLogger`.
13
+ * @returns The normalized redaction settings.
14
+ */
15
+ export declare function resolveRedactionOptions(redact: boolean | LoggerRedactionOptions | undefined): LoggerRedactionOptions;
16
+ //# sourceMappingURL=loggerOptions.redact.d.ts.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Normalization of the `redact` logger option.
3
+ */
4
+ /**
5
+ * Resolves the `redact` option into frozen redaction settings.
6
+ *
7
+ * `false` turns redaction off and `true` (or omitting it) keeps the default.
8
+ * An object is used as given. Spreading `false` into an object yields `{}`,
9
+ * which is the default, so a boolean must be mapped explicitly.
10
+ *
11
+ * @param redact - The `redact` value passed to `createLogger`.
12
+ * @returns The normalized redaction settings.
13
+ */
14
+ export function resolveRedactionOptions(redact) {
15
+ if (redact === false)
16
+ return Object.freeze({ enabled: false });
17
+ if (redact === true || redact === undefined || redact === null) {
18
+ return Object.freeze({});
19
+ }
20
+ return Object.freeze({ ...redact });
21
+ }
22
+ //# sourceMappingURL=loggerOptions.redact.js.map
@@ -24,9 +24,10 @@ export interface LoggerOptions {
24
24
  * Redaction is ON by default: fields whose NAME looks like a secret
25
25
  * (password, token, api key, credential, authorization, cookie) are
26
26
  * replaced with "[REDACTED]" before an entry reaches a formatter.
27
- * Pass `{ enabled: false }` to opt out.
27
+ * Pass `false` (or `{ enabled: false }`) to opt out, or an options object
28
+ * to customize the matched keys, pattern and replacement.
28
29
  */
29
- readonly redact?: LoggerRedactionOptions;
30
+ readonly redact?: boolean | LoggerRedactionOptions;
30
31
  }
31
32
  /** Options used when creating a child logger. */
32
33
  export interface ChildLoggerOptions {
@@ -1,4 +1,5 @@
1
1
  import { LoggerLevel, resolveLoggerLevel, } from "../loggerLevel/loggerLevel.type.js";
2
+ import { resolveRedactionOptions } from "./loggerOptions.redact.js";
2
3
  /** Default logger configuration values. */
3
4
  export const DEFAULT_LOGGER_OPTIONS = {
4
5
  enabled: true,
@@ -43,7 +44,7 @@ export function resolveLoggerOptions(options = {}) {
43
44
  transportTimeout: options.transportTimeout ?? DEFAULT_LOGGER_OPTIONS.transportTimeout,
44
45
  inheritContext: options.inheritContext ?? DEFAULT_LOGGER_OPTIONS.inheritContext,
45
46
  mutable: options.mutable ?? DEFAULT_LOGGER_OPTIONS.mutable,
46
- redact: Object.freeze({ ...(options.redact ?? {}) }),
47
+ redact: resolveRedactionOptions(options.redact),
47
48
  });
48
49
  }
49
50
  /** Merges two logger option objects. Values from `override` take precedence. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zudojs/logger",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Structured logging with transports, log levels, and context propagation for Zudojs applications.",
5
5
  "license": "MIT",
6
6
  "author": {