bind abstract method

Interface bind([
  1. Iterable<Field>? fields
])

Creates and returns a new logging context with bound collection of fields added to existing one.

Example:

final context = logger.bind({
  Str('username', 'vanesyan'),
  Str('filename', 'avatar.png'),
  Str('mime', 'image/png'),
});

final tracer = context.trace('Uploading!', Level.info);

// Emulate uploading, wait for 1 sec.
await Future<void>.delayed(const Duration(seconds: 1));

tracer.stop('Aborting...');
context.fatal('Failed to upload!');

It is possible to extend bound context with another fields.

Example:

var context = logger.bind({Str('first', '1st'}); // => { "first": "1st" }
context = context.bind({Str('second', '2nd'}); // => { "first": "1st", "second": "2nd" }

Implementation

Interface bind([Iterable<Field>? fields]);