fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.12k stars 281 forks source link

Logs not showing no matter the macro invocation #2243

Closed zhpixel517 closed 3 weeks ago

zhpixel517 commented 4 weeks ago

Describe the bug

I'm trying to get some logs to show up in the console when I run my app. I have tried calling println!, debug!, info! and warn!, and no matter which I call, none of the messages I try to print show up.

Steps to reproduce

Create a new project, and make a function called test_logs() and try this:

 debug!("Called debug");
 println!("Called println");
 info!("called info");
 warn!("called warn");

run the generate command and call this function immediately, inside initState(), perhaps.

and the output looks like this for me:

 Launching lib/main.dart on iPhone in debug mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: 27J95Y9584
Xcode build done.                                           28.4s
You may be prompted to give access to control Xcode. Flutter uses Xcode to run your app. If access is not allowed, you can change this through your Settings > Privacy & Security > Automation.
Connecting to VM Service at ws://127.0.0.1:61019/Qt697_cX2HA=/ws

... nothing. I verified that the flutter_rust_bridge::setup_default_user_utils() was present. I also tried manually configuring this following example 2 in the logging doc to no success either, and made sure to add the correct bundle ID for ios as well.

Where am I going wrong here?

Logs

(logs would be too long to include. there are no errors when running the codegen)

Expected behavior

No response

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Additional context

No response

dikatok commented 4 weeks ago

@fzyzcjy is this related to https://github.com/fzyzcjy/flutter_rust_bridge/discussions/2240?

zhpixel517 commented 4 weeks ago

For extra context, this is my Cargo.toml:

[package]
name = "rust_lib_flutter_rust_test"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "staticlib"]

[dependencies]
android_logger = "0.14.1"
cpal = "0.15.3"
opus = {path = "../../../RustPlayground/opus-rs"}
flutter_rust_bridge = "=2.1.0"
jni = "0.21.1"
log = "0.4.22"
ndk-context = "0.1.1"
rtcp = "0.11.0"
rtp-rs = "0.6.0"
rtrb = "0.3.1"
socket2 = "0.5.7"

[target.'cfg(any(target_os = "ios"))'.dependencies]
oslog = "0.2.0"
fzyzcjy commented 4 weeks ago

@dikatok I think it is possible!

fzyzcjy commented 4 weeks ago

I also tried manually configuring this following example 2 in the logging doc to no success either

Hmm, maybe try the underlying mechanism of that logging helper, i.e. call low-level things to directly log to system and see whether it works. Also maybe ask/discuss on the related crates (oslog for example), and/or rust forum, since it looks like a general Rust question "why logging does not work" and may not be related to frb core.

wxitcode commented 4 weeks ago

Approach 1: Use the default one

Setps:

  1. add log feature as below
  2. init log
  3. for ios (oslog), you can view the log with Instruments or Console App on macOS; for macos (oslog), same as ios. version 2.2.0 only for ios, so just wait for new version release.; for android (android_logger), you can view with adb logcat
[dependencies]
flutter_rust_bridge = { version = "=2.2.0", features = ["log"] }
log = "0.4.22"
use log::info;

#[flutter_rust_bridge::frb(sync)] // Synchronous mode for simplicity of the demo
pub fn greet(name: String) -> String {
    println!("hello world");
    info!("log:hello world");
    format!("Hello, {name}!")
}

#[flutter_rust_bridge::frb(init)]
pub fn init_app() {
    // Default utilities - feel free to customize
    flutter_rust_bridge::setup_default_user_utils();
}

View all logs in one place. just try other Approach, such as Example 4: Send Rust logs to Dart Example 5: A step-by-step guide to send Rust logs to Dart

dikatok commented 4 weeks ago

Approach 1: Use the default one

Setps:

  1. add log feature as below
  2. init log
  3. for ios (oslog), you can view the log with Instruments or Console App on macOS; for macos (oslog), same as ios. version 2.2.0 only for ios, so just wait for new version release.; for android (android_logger), you can view with adb logcat
[dependencies]
flutter_rust_bridge = { version = "=2.2.0", features = ["log"] }
log = "0.4.22"
#[flutter_rust_bridge::frb(init)]
pub fn init_app() {
    // Default utilities - feel free to customize
    flutter_rust_bridge::setup_default_user_utils();
}

View all logs in one place. just try other Approach, such as Example 4: Send Rust logs to Dart Example 5: A step-by-step guide to send Rust logs to Dart

Are the logs emitted by rust layer not exposed to flutter debug console by default?

Update Checked adb logcat and it yield no results as well. Will try using FRB as flutter app not as plugin later, and see if it works.

dikatok commented 4 weeks ago

I created new app using flutter_rust_bridge_codegen create my_app, added log macros warn, info, error, none are emitted in either flutter debug console or adb logcat. 😢

fzyzcjy commented 4 weeks ago

I still guess it is probably an issue with the specific logging library, instead of a frb (core) issue. So asking/searching there may help, since the logging lib maintainers have more experience about what is going wrong than me about the logging library.

wxitcode commented 4 weeks ago

@dikatok

I created new app using flutter_rust_bridge_codegen create my_app, added log macros warn, info, error, none are emitted in either flutter debug console or adb logcat. 😢

Did you follow the steps above?
You should enable log feature flutter_rust_bridge = { version = "=2.2.0", features = ["log"] }

For Android Note: adb logcat is just used for Android logs and even without use logcat you can see the log like this I/rust_lib_xxx::xx..(pid number): hello world in the console, When you debug android.

Currently frb v2.2.0, the default utils only for Android and iOS, you can customize for support other platforms.

zhpixel517 commented 4 weeks ago

enabling the log feature allows debug!, info!, and warn! to show, but not println!. also, a manual panic! invocation isn't showing either. I'll look around on the platform specific logging crates to see if I can find anything that could help

edit: nevermind, panics are showing

fzyzcjy commented 3 weeks ago

println will not show iirc because it is a builtin thing and cannot be very easily configured. happy to see it works!

so, shall we make the log feature default enabled?

github-actions[bot] commented 1 week ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.