Skip to content

fix(logging): enable redaction by default when global rules exist #40

@galligan

Description

@galligan

Problem

Redaction is gated on redactionConfig?.enabled, so even if the user calls configureRedaction() with patterns, logs won't be redacted unless they also pass redaction: { enabled: true } to createLogger.

Current behavior:

// Configure global redaction patterns
configureRedaction({
  keys: ["apiKey", "password"],
  patterns: [/sk-[a-zA-Z0-9]+/g],
});

// This logger will NOT redact because enabled defaults to false
const logger = createLogger({ name: "my-app" });
logger.info("Request", { apiKey: "secret" }); // "secret" is NOT redacted

Expected behavior:

// Same setup as above...
const logger = createLogger({ name: "my-app" });
logger.info("Request", { apiKey: "secret" }); // "secret" IS redacted (because global rules exist)

Proposed Solution

In createLogger(), check if global redaction rules exist before skipping redaction:

const hasGlobalRules = 
  (globalRedactionConfig.patterns?.length ?? 0) > 0 || 
  (globalRedactionConfig.keys?.length ?? 0) > 0;

if ((redactionConfig && redactionConfig.enabled !== false) || hasGlobalRules) {
  // Apply redaction...
}

Location

packages/logging/src/index.ts around line 522-523

Origin

PR review feedback @b4d5b on #31


🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions