withFields abstract method
Creates and returns a new logging context with bound collection of
fields
added to existing ones.
Example:
final context = logger.withFields({
Str('username', 'roman-vanesyan'),
Str('filename', 'avatar.png'),
Str('mime', 'image/png'),
});
final timer = context.startTimer('Uploading!', Level.info);
// Emulate uploading, wait for 1 sec.
await Future<void>.delayed(const Duration(seconds: 1));
timer.stop('Aborting...');
context.fatal('Failed to upload!');
It is possible to extend bound context with another fields.
Example:
var context = logger.withFields({Str('first', '1st'}); // => { "first": "1st" }
context = context.withFields({Str('second', '2nd'}); // => { "first": "1st", "second": "2nd" }
Implementation
Interface withFields(Iterable<Field> fields);