Skip to content

hap-fluent / createChildLogger

Function: createChildLogger()

ts
function createChildLogger(context): Logger;

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

Create a child Pino logger with additional bound context fields.

Parameters

ParameterTypeDescription
contextRecord<string, unknown>Key-value pairs to bind to every log message.

Returns

Logger

A pino.Logger child instance with the given context fields.

Remarks

Every message emitted by the child logger automatically includes the context fields, making it easy to correlate logs for a specific device, service, or characteristic without manually adding fields to each log call.

The child logger uses the same level and transport as the root logger returned by getLogger. Re-configure the root logger via configureLogger if you need to change the level globally.

Example

typescript
const deviceLogger = createChildLogger({
  device: 'living-room-light',
  deviceId: '12345'
});

deviceLogger.info('State changed');
// Output: { "device": "living-room-light", "deviceId": "12345", "msg": "State changed" }

Released under the Apache-2.0 License.