flutter_xlog_ffi 0.0.1
flutter_xlog_ffi: ^0.0.1 copied to clipboard
A Flutter FFI plugin that packages Tencent mars xlog for Android and iOS logging.
flutter_xlog
A Flutter FFI plugin for Tencent mars xlog on Android and iOS.
flutter_xlog #
flutter_xlog packages Tencent mars xlog behind a small Flutter FFI API. It
ships with native artifacts for Android and iOS, so Flutter apps can write logs
through xlog without compiling mars inside the host app.
Usage #
Add the dependency:
dependencies:
flutter_xlog: ^0.0.1
Import it:
import 'package:flutter_xlog/flutter_xlog.dart';
Initialize xlog before writing logs:
FlutterXLog.instance.init(
logDir: '/path/to/logs',
cacheDir: '/path/to/cache',
prefixName: 'myapp',
level: XLogLevel.debug,
mode: XLogMode.async,
cacheDays: 3,
consoleLogOpen: true,
);
Write and flush logs:
FlutterXLog.instance.i('Home', 'page opened');
FlutterXLog.instance.e('Network', 'request failed');
FlutterXLog.instance.flush(sync: true);
Close the logger when it is no longer needed:
FlutterXLog.instance.close();
Features #
- Flutter FFI API: Access mars xlog through a compact Dart wrapper.
- Android and iOS: Includes native artifacts for both mobile platforms.
- Log lifecycle control: Initialize, write, flush, and close logs from Dart.
- Console log switch: Enable native console logging when debugging.
- Public key support: Configure an xlog public key before initialization.
- Async or sync mode: Choose the xlog mode that matches your runtime needs.
Public key #
Set a public key before init() if your xlog build uses encrypted logs:
FlutterXLog.instance.setPublicKey('your public key');
FlutterXLog.instance.init(
logDir: '/path/to/logs',
cacheDir: '/path/to/cache',
);
You can also pass the key directly to init(publicKey: ...).
Platform notes #
Android #
The package includes Android shared libraries for:
armeabi-v7aarm64-v8a
The host app is still responsible for packaging native libraries correctly. For Android devices with 16 KB page size, validate the final APK or AAB.
iOS #
The package includes ios/Frameworks/flutter_xlog.xcframework for iOS device
and simulator builds.
Example #
See example/ for a minimal Flutter app that initializes xlog, writes sample
logs, flushes them, and closes the logger.
cd example
flutter pub get
flutter run