exportHierarchy static method

Map<String, dynamic> exportHierarchy()

Exports the registry configuration hierarchy.

Returns a map representation of the active loggers and their configuration states, including explicit, frozen, inherited, and effective fields.

Each entry contains:

  • 'explicit': Fields explicitly set by Logger.configure on this node.
  • 'frozen': Fields baked in by freezeInheritance.
  • 'inherited': Fields resolved dynamically from ancestor loggers.
  • 'implicit': true if this logger was only materialised by Logger.get and was never passed to Logger.configure.
  • 'effective': Resolved field values as JSON-serialisable primitives. Useful for crash diagnostics and debug overlays.

Implementation

static Map<String, dynamic> exportHierarchy() {
  final map = <String, dynamic>{};
  final sortedKeys = _registry.keys.toList()..sort();
  for (final n in sortedKeys) {
    final logger = Logger.get(n);
    final config = _registry[n]!;

    // Build effective map with JSON-serialisable primitives.
    final smc = logger.stackMethodCount;
    final effective = <String, dynamic>{
      'enabled': logger.enabled,
      'logLevel': logger.logLevel.name,
      'includeFileLineInHeader': logger.includeFileLineInHeader,
      'includeOrigin': logger.includeOrigin,
      'stackMethodCount': {
        for (final e in smc.entries) e.key.name: e.value,
      },
      'timestamp': logger.timestamp.formatter.pattern,
      'stackTraceParser': logger.stackTraceParser.ignorePackages.toString(),
      'handlers': logger.handlers
          .map(
            (final h) => '${h.formatter.runtimeType}(${h.sink.runtimeType})',
          )
          .toList(),
      'autoSinkBuffer': logger.autoSinkBuffer,
    };

    map[n] = {
      'explicit': logger.explicitFields.toList(),
      'frozen': logger.frozenFields.toList(),
      'inherited': logger.inheritedFields.toList(),
      'implicit': config.implicit,
      'effective': effective,
    };
  }
  return map;
}