// Wrapper around dart:developer.log that also outputs logs in release mode.
//
// Usage: import this file as `developer` instead of `dart:developer`.
// Then call `developer.log(...)` as usual. In debug/profile, it forwards to
// dart:developer.log; in release it prints to stdout so logs are visible.
export 'dart:developer' hide log;

import 'dart:async' show Zone;
import 'dart:developer' as dev;
import 'package:flutter/foundation.dart';

void log(
  String message, {
  DateTime? time,
  int? sequenceNumber,
  int level = 0,
  String name = '',
  Zone? zone,
  Object? error,
  StackTrace? stackTrace,
}) {
  if (kReleaseMode) {
    final ts = (time ?? DateTime.now()).toIso8601String();
    final tag = name.isNotEmpty ? '[$name] ' : '';
    final seq = sequenceNumber != null ? ' #$sequenceNumber' : '';
    final lvl = level != 0 ? ' L$level' : '';
    final err = error != null ? ' | error: $error' : '';
    final st = stackTrace != null ? ' | stack: $stackTrace' : '';
    // Keep it a single line to avoid mixing with platform loggers.
    // Using print to ensure output in release builds.
    // Example: 2025-09-13T12:47:00.123Z [StompService] Connected ... L800 #42
    // Note: Some platforms may trim long lines; we still prefer a single print.
    // ignore: avoid_print
    print('$ts $tag$message$seq$lvl$err$st');
  } else {
    dev.log(
      message,
      time: time,
      sequenceNumber: sequenceNumber,
      level: level,
      name: name,
      zone: zone,
      error: error,
      stackTrace: stackTrace,
    );
  }
}
