Unified logging

DartNative unifies Dart, Swift and Kotlin logs into one stream in your terminal, and can persist every session to a file on the device — so even a TestFlight build that dies before its first frame leaves a log you can pull.

One stream, both worlds

Cross-platform debugging usually means two consoles. On iOS, native-side logs land in Xcode’s console and don’t reliably reach your flutter run terminal — a known, still-open issue that depends on iOS version and how the app was launched. React Native’s own docs point you to Xcode for native logs; JavaScript logs live in React Native DevTools (Metro stopped mirroring them in 0.77).

In DartNative the unified stream is first-party. Log with dnLog from either side and it appears — interleaved, in order — in the terminal you’re already watching:

// Dart
dnLog('[MyScreen] user tapped button');
// Swift (plugins, native callbacks)
dnLog("[MyPlugin] gesture recognised at \(point)")

Use dnLog instead of bare print() — it’s what guarantees capture from any context, including native callbacks, and it’s what feeds file persistence below. Plugins written in C / Objective-C can call DNAppendLog("...").

Setup

Wrap your app in DartNativeLogger.run — this is also where verbose framework logging and file persistence are switched on:

import 'package:dartnative/dartnative.dart';

void main() {
  DartNativeLogger.run(
    () {
      registerNativeBindings(IOSNativeBindings.instance);
      runApp(const MyApp());
    },
    verbose: false,     // framework-internal diagnostics
    saveToFile: true,   // persist every session to a log file
  );
}
ParameterDefaultDescription
verbosefalseFramework-internal logs (reconciler, navigation, layout)
saveToFilefalsePersist the session’s output to a file on the device
filePathautoOverride the log file location

Session files — saveToFile

With saveToFile: true, every launch appends to one fixed file (default: dartnative_session.log in the app’s temp directory — the exact path is printed at startup), each run marked with its own === dartnative session <time> === header. The path never changes, so a crashed session’s tail is right there after you relaunch.

The file caps itself: once it passes 1 MiB it rolls over to a dartnative_session.log.old sidecar and a fresh file starts. The two together always hold the newest 1–2 MiB of history, so disk use tops out around 2 MB — that cap is what makes the flag safe to ship in production, and a rollover is an O(1) rename that never touches the write path.

Logs drain to disk progressively while the app runs, and are force-flushed when the app is backgrounded — so a session that crashes at boot or is killed while suspended still keeps its tail.

Pull the logs off a device:

xcrun devicectl device copy from --device <udid> \
  --domain-type appDataContainer --domain-identifier <bundle-id> \
  --source tmp --destination ./device_logs

Debugging a TestFlight build that won’t start

A release build on a tester’s phone has no terminal attached and no debugger — if it hangs on the splash screen, there’s no crash report to read. The persisted session log is your visibility.

Pair saveToFile: true with boot breadcrumbs — cheap one-liners between the awaits in main():

Future<void> main() async {
  await DartNativeLogger.run(
    () async {
      DartNativePluginRegistrant.registerAll();
      dnLog('[boot] plugins registered');

      registerSkiaFactories();
      dnLog('[boot] skia registered');

      await AppConfig.load();
      dnLog('[boot] config loaded');

      dnLog('[boot] runApp');
      runApp(const App());
    },
    saveToFile: true,
  );
}

Reading a pulled log: scroll to the last === dartnative session … === header — that’s the run you care about. A healthy session is several KB; one that ends right after a breadcrumb means main() died on the next step, and the last line present names your suspect. This exact pattern has diagnosed a production splash-screen hang that existed only in the App Store–processed binary, where no debugger could ever attach.

API summary

APIWherePurpose
dnLog(message)DartApp-level log, captured from any context
dnLog(message)Swift / KotlinNative-side log into the same stream
DNAppendLog(ptr)C / Obj-CNative log for plugins that can’t link Swift
DartNativeLogger.flush()DartForce buffered lines to disk (rarely needed)
DartNativeLogger.filePathDartAbsolute path of the active session log