flutter_logger 0.2.0

logging library for using rust together with flutter/dart and flutter_rust_bridge
Documentation

flutter_logger

logging library for using rust together with flutter/dart and flutter_rust_bridge to get logs from rust into your app.

features

  • panic: print rust panics to the log stream

usage

This code is not complete. Look into the example folder for a full working example.

rust

pub fn test(i: i32) {
		// using own macros
		logi!("test called with: {i}");
		// using the 'log' crate macros
		info!("test called with: {i}")
}

pub fn init(sink: StreamSink<LogEntry>) {
		flutter_logger::init(sink).unwrap();
}

dart/flutter

final rust_lib =
void setupLogger(){
		rustLib.init().listen((msg){
			// This should use a logging framework in real applications
			print("${msg.logLevel} ${msg.lbl.padRight(8)}: ${msg.msg}");
		});
}

void main(){
	setupLogger();
	rustLib.test(i: 5);
}

This works also on mobile apps like Android where println() in rust isn't shown in the console.