shorten static method

String shorten(
  1. String text,
  2. int maxLen
)

limit log info

Implementation

static String shorten(String text, int maxLen) {
  assert(maxLen > 128, 'too short: $maxLen');
  int size = text.length;
  if (size <= maxLen) {
    return text;
  }
  String desc = 'total $size chars';
  int pos = (maxLen - desc.length - 10) >> 1;
  if (pos <= 0) {
    return text;
  }
  String prefix = text.substring(0, pos);
  String suffix = text.substring(size - pos);
  return '$prefix ... $desc ... $suffix';
}