Skip to content

hap-fluent / configureLogger

Function: configureLogger()

ts
function configureLogger(options?): Logger;

Defined in: packages/hap-fluent/src/logger.ts:130

Configure the global hap-fluent logger instance.

Parameters

ParameterTypeDescription
optionsLoggerOptionsLoggerOptions controlling level, pretty-print, etc.

Returns

Logger

The newly configured pino.Logger instance.

Remarks

Call this once at the start of your plugin's lifecycle (e.g., in the platform constructor) before any hap-fluent operations. Subsequent calls replace the existing logger instance entirely — all child loggers created before the replacement will continue to use the old instance.

Use When

  • Setting up structured logging at plugin startup with a custom level or base context fields.
  • Switching between development (pretty) and production (JSON) output.

Avoid When

  • You only need a read reference to the current logger — use getLogger instead.

Pitfalls

  • NEVER call configureLogger inside a GET/SET handler — reconstructing the logger on every HomeKit poll is a significant performance overhead.
  • NEVER enable pretty: true in production — pino-pretty adds ~1ms of synchronous formatting overhead per log line, which can cascade under high-frequency characteristic polling.

Example

typescript
// Development mode with pretty printing
configureLogger({ level: 'debug', pretty: true });

// Production mode with JSON output and plugin context
configureLogger({
  level: 'info',
  pretty: false,
  base: { plugin: 'my-homebridge-plugin', version: '1.0.0' }
});

Released under the Apache-2.0 License.