publish method

  1. @override
void publish(
  1. LogMessage message
)
override

Implementation

@override
void publish(LogMessage message) {
  if (_logLevel > message.severity) {
    return;
  }

  final color = _severityColor(message.severity);

  var prefixLength = 0;
  void writePrefix(String val) {
    prefixLength += val.length;
    stdout.write(val);
  }

  writePrefix(_timestampString(message.timestamp));
  writePrefix(' ');

  if (color != null) {
    stdout.write(color);
  }

  writePrefix(_severityPrefix(message.severity));
  writePrefix(' ');

  final pathInfo = [
    Zone.current[#apiRequestId],
    Zone.current[#schedulerExecutionId],
    message.sender,
    //TODO other log path segments
  ];

  for (final entry in pathInfo.whereNotNull) {
    writePrefix(_brackets(entry.toString(), null));
    writePrefix(' ');
  }

  final indent = ' ' * prefixLength;
  stdout.write(message.message.replaceAll('\n', '\n$indent'));

  if (message.exception != null) {
    stdout.write('\n');
    stdout.write(indent);
    stdout.write(message.exception);
  }

  if (message.trace != null) {
    stdout.write('\n');
    stdout.write(indent);
    stdout.write(message.trace.toString().replaceAll('\n', '\n$indent'));
  }

  if (color != null) {
    stdout.write(_colorReset);
  }
  stdout.write('\n');
}