Skip to content

StaticFileHandler uses raw console.error/console.warn instead of configurable logger #189

@VikramAditya33

Description

@VikramAditya33

StaticFileHandler logs errors via hardcoded console.error and console.warn. This bypasses the user's configured logger and is inconsistent with the rest of the platform (UwsPlatformAdapter, RouteRegistry), which both accept an optional logger and fall back to console.

Lines 255 and 447:

console.error('Static file serving failed:', { filePath, error: err });
// ...
console.warn('Worker pool read failed, falling back to stream:', { filePath, error: err });

Proposed Fix

  1. Add optional logger to StaticFileOptions
// src/http/handlers/static/static-file-handler.ts
import type { Logger } from '../../../shared/interfaces';

export interface StaticFileOptions {
  // ...existing options...
  /**
   * Custom logger for static file errors
   * Defaults to console if not provided
   */
  logger?: Logger;
}
  1. Store a normalized logger in the handler
constructor(options: StaticFileOptions) {
  // ...existing setup...
  
  this.logger = {
    error: options.logger?.error?.bind(options.logger) || console.error.bind(console),
    warn: options.logger?.warn?.bind(options.logger) || console.warn.bind(console),
  };
}
  1. Replace console calls with this.logger
// Line 255
this.logger.error('Static file serving failed', { filePath, error: err });

// Line 447
this.logger.warn('Worker pool read failed, falling back to stream', { filePath, error: err });
  1. Pass the adapter's logger through in useStaticAssets
// src/http/platform/uws-platform.adapter.ts line 766
const handler = new StaticFileHandler({
  root: path,
  logger: this.logger, // ← pass adapter logger
  ...handlerOptions,
});

Metadata

Metadata

Labels

bugSomething isn't workinggood first issueGood for newcomers

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions