ansiPrint function

String ansiPrint(
  1. dynamic msg, {
  2. DateTime? date,
  3. Level level = Level.debug,
  4. String? service,
  5. String? module,
  6. DateFormat? dateFormat,
  7. LoggerOptions options = defaultLevelOptions,
  8. bool shouldPrint = true,
})

Implementation

String ansiPrint(
  msg, {
  DateTime? date,
  Level level = Level.debug,
  String? service,
  String? module,
  DateFormat? dateFormat,
  LoggerOptions options = defaultLevelOptions,
  bool shouldPrint = true,
}) {
  service ??= Platform.localHostname;
  dateFormat ??= defaultDateFormat;
  date ??= DateTime.now();
  final mService = textToAnsi(service, style: options.service, enableAnsi: options.enableAnsi);
  final mModule = module == null ? '' : ':${textToAnsi(module, style: options.module, enableAnsi: options.enableAnsi)}';
  final mDate = textToAnsi('[${dateFormat.format(date)}]', style: options.date, enableAnsi: options.enableAnsi);
  final levelStyle = level.logStyleFromOptions(options);
  final mLevel = textToAnsi(levelStyle.item1, style: levelStyle.item2, enableAnsi: options.enableAnsi);
  final log = '$mDate $mLevel $mService$mModule $msg';
  if (shouldPrint) print(log);
  return log;
  // date, level, module, msg
}