Service for sanitizing log messages to remove sensitive information.
Adopters can rebind this service to customize sanitization behavior, for example to mask additional patterns like API keys or tokens.
// Custom sanitizer that extends the default behavior@injectable()class CustomLoggerSanitizer extends DefaultLoggerSanitizer { override sanitize(message: string): string { let sanitized = super.sanitize(message); // Add custom sanitization, e.g., mask API keys sanitized = sanitized.replace(/api[_-]?key[=:]\s*['"]?[\w-]+['"]?/gi, 'api_key=****'); return sanitized; }}// In your module:rebind(LoggerSanitizer).to(CustomLoggerSanitizer).inSingletonScope(); Copy
// Custom sanitizer that extends the default behavior@injectable()class CustomLoggerSanitizer extends DefaultLoggerSanitizer { override sanitize(message: string): string { let sanitized = super.sanitize(message); // Add custom sanitization, e.g., mask API keys sanitized = sanitized.replace(/api[_-]?key[=:]\s*['"]?[\w-]+['"]?/gi, 'api_key=****'); return sanitized; }}// In your module:rebind(LoggerSanitizer).to(CustomLoggerSanitizer).inSingletonScope();
Sanitizes a log message by masking sensitive information.
The log message to sanitize
The sanitized message with sensitive data masked
Service for sanitizing log messages to remove sensitive information.
Adopters can rebind this service to customize sanitization behavior, for example to mask additional patterns like API keys or tokens.
Example