json static method

void json(
  1. Object? object, {
  2. String tag = 'Reactiv',
  3. LogLevel level = LogLevel.debug,
})

Log a JSON object with pretty formatting

Implementation

static void json(
  Object? object, {
  String tag = 'Reactiv',
  LogLevel level = LogLevel.debug,
}) {
  if (!config.enabled || level.index < config.minLevel.index) return;

  try {
    final prettyString = config.prettyJson
        ? const JsonEncoder.withIndent('  ').convert(object)
        : jsonEncode(object);

    _log(level, prettyString, tag: tag);
  } catch (e) {
    _log(
      LogLevel.error,
      'Failed to encode JSON: $e\nObject: $object',
      tag: tag,
    );
  }
}