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
| Parameter | Type | Description |
|---|---|---|
options | LoggerOptions | LoggerOptions 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
configureLoggerinside a GET/SET handler — reconstructing the logger on every HomeKit poll is a significant performance overhead. - NEVER enable
pretty: truein 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' }
});