createPrinter static method
Returns a function that accepts a LogRecord and prints it using customPrint
in given format
.
format
should be a raw string that otherwise would be a valid interpolation.
You can refer to any property of LogRecord or some special properties:
${level.name}
- this will return a string with a name associated with the level.
Example
var printer = LogRecord.createPrinter(r'$time: $message');
logger.stream.listen(printer);
Implementation
static void Function(LogRecord) createPrinter(String format,
{Function(String s) customPrint = print}) {
return (LogRecord record) {
var message = format
.replaceAll(r'$time', record.time.toString())
.replaceAll(r'$level', record.level.toString())
.replaceAll(r'${level.name}', Level.getName(record.level))
.replaceAll(r'$message', record.message.toString())
.replaceAll(r'$scope', record.scope.toString())
.replaceAll(r'$stackTrace', record.stackTrace.toString())
.replaceAll(r'$zone', record.zone.toString())
.replaceAll(r'$id', record.id.toString());
customPrint(message);
};
}