Repository navigation
Closed
Labels
P2Important issues not at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.engineflutter/engine related. See also e: labels.found in release: 1.22Found to occur in 1.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: toolingAffects the flutter_plugin_tools packagepackageflutter/packages repository. See also p: labels.platform-iosiOS applications specifically
Description
Steps to Reproduce
Create a swift plugin project.
flutter create -i swift -t plugin print_repro
Modify ios/Classes/SwiftPrintReproPlugin.swift to add a print statement in the handle function, like so:
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
print("hi!")
result("iOS " + UIDevice.current.systemVersion);
}Run.
flutter run or flutter run -v.
Expected output: “hi!” In console but none seen.
Flutter Doctor
$ flutter doctor
[✓] Flutter (on Mac OS X 10.12.6 16G1036, locale en-US, channel master)
• Flutter at /Users/pquitslund/src/repos/flutter
• Framework revision d79c12e5b8 (4 days ago), 2017-11-22 17:35:35 +0100
• Engine revision 93b2179597
• Tools Dart version 1.25.0-dev.11.0
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.1)
• Android SDK at /Users/pquitslund/Library/Android/sdk
• Unable to locate Android NDK.
• Unable to locate compiler in Android NDK.
• Platform android-27, build-tools 27.0.1
• Java binary at: /Applications/Tools/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.1, Build version 9B55
• ios-deploy 1.9.2
• CocoaPods version 1.3.1
[✓] Android Studio (version 3.0)
• Android Studio at /Applications/Tools/Android Studio.app/Contents
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)
[✓] IntelliJ IDEA Community Edition (version 2017.2.6)
• Flutter plugin version 19.1
• Dart plugin version 172.4343.25
[✓] Connected devices
• iPhone 8 • B9BDC7A5-52E3-46E3-BF70-E7A4B0BFEAAE • ios • iOS 11.1 (simulator)
/cc @cbracken @szakarias
Reacted by Neil Jay Warner, Arto Bendiken, eredacokmerke, Tim Traversy, Markus Michel, magicly, hisaichi5518, Xavier H., Moh Badjah, Mahdi Moosavi and 14 more
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.engineflutter/engine related. See also e: labels.found in release: 1.22Found to occur in 1.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: toolingAffects the flutter_plugin_tools packagepackageflutter/packages repository. See also p: labels.platform-iosiOS applications specifically
Activity
pq commentedon Nov 27, 2017
FWIW:
NSLOG(..)does work so that's a good interim solution. 👍szakarias commentedon Nov 28, 2017
I actually don't know what to expect for
printbut if you run it from xcode you can see it in the xcode console. Maybe @xster knows more?pq commentedon Nov 28, 2017
Chatting w/ @cbracken, I think the expectation is that output would make its way to the Flutter console. (FWIW running from Xcode isn't an easy option if you're debugging plugin integration but you're spot on that its handy for what you can test that way, though it may be surprising to see it in the Xcode console but not in Flutter's...) Incidentally, whatever the answer is, it might be good thing to document logging best practices in the plugin development docs (cc @LarkAscending).
cbracken commentedon Nov 28, 2017
Flutter console logging relies on device logging which, depending on iOS version, is implemented as syslog, ASL, or os_log.
NSLog()(andos_log()on iOS 10 and later) logs to the device logs, which is what flutter bridges to theflutter runoutput.printanddebugPrintdon't log to the device log, and therefore don't get bridged across.While the behaviour is consistent with native Swift apps from the perspective of where each function logs to, the question is what developers expect. I'd wager most developers will expect output consistent with the Xcode console, not with the device syslog.
The fix here is most likely to stop relying on device logs for debug printing and instead rely on a more direct bridging mechanism.
For later reference if we need it, here's the
flutter runoutput I see in verbose mode (and in Console.app) from a series of all four log calls:pq commentedon Nov 29, 2017
👍
This is my thinking exactly. In any event, I think it would be good to document this somewhere.
FYI @devoncarew who has been thinking about improved logging from the IDE perspective
devoncarew commentedon Nov 29, 2017
Sounds great. For logging, I was thinking about log streams that you'd want to enable / disable / filter (to focus in on some things like networking, and reduce the verbosity of others).
printshould likely just always show to the user :)@cbracken, in terms of bridging, we wouldn't necessarily need to do anything iOS specific here. If we have
printroute it's output to thedart:developerlog()call, IDEs (or other) could get those calls via the service protocol and display in the console as if it were print output.cbracken commentedon Dec 1, 2017
To be clear,
printhere is the Swift function (implemented inlibswiftfoundation.dylib), not Dart's coreprint(whose implementation we have direct control over) so we'll need to do a little bit of poking around to see where it's writing today.If
printanddebugPrintare writing tostdout, that's something we could likely intercept in the engine and forward over the service protocol as you suggest. Agreed we don't want to do something platform-specific here.I'd also like to make sure whatever solution we implement doesn't use the current bridging mechanism (logs), since redirecting these calls to logs goes against developer expectations on the platform, and could result in unwittingly logging PII, etc. Forwarding over the service port seems nice -- with the notable exception of the initial logging of the observatory port itself ;-).
abacaj commentedon Aug 29, 2018
Does anyone know if this is fixed?
I see no log output using print or NSLog from plugin code.
robsonql commentedon Sep 21, 2018
Same problem here. Please look at this issue.
jmrboosties commentedon Oct 9, 2018
Would really appreciate if we had a way to see the console on an iOS bridge running Swift. I can't see it in Xcode either which wouldn't be a huge deal for me if that's where the output was found, just right now I can't find it anywhere.
mobiletoly commentedon Nov 22, 2018
print does not work for me. NSLog initially didn't work as well, until I encountered some really odd behavior that makes NSLog to work (well, kind of)
So square brackets are the key here. "Test" part is not going to be printed but everything after first %@ with associated [] argument - will be printed. Don't ask why :)
17 remaining items
jmagman commentedon Oct 20, 2020
#54781 resolved this in 1.23.0-7.0.pre which is available on the beta channel.
TahaTesser commentedon Oct 22, 2020
Updated
Confirm it works
logs
flutter doctor -v
[✓] Flutter (Channel beta, 1.23.0-18.1.pre, on Mac OS X 10.15.7 19H2 x86_64, locale en-GB) • Flutter version 1.23.0-18.1.pre at /Users/tahatesser/Code/flutter_beta • Framework revision 198df796aa (7 days ago), 2020-10-15 12:04:33 -0700 • Engine revision 1d12d82d9c • Dart version 2.11.0 (build 2.11.0-213.1.beta) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/tahatesser/Code/sdk • Platform android-30, build-tools 30.0.2 • ANDROID_HOME = /Users/tahatesser/Code/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 12.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.1, Build version 12A7403 • CocoaPods version 1.10.0.rc.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] VS Code (version 1.50.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.15.1 [✓] Connected device (4 available) • Taha’s iPhone (mobile) • 00008020-001059882212002E • ios • iOS 14.1 • iPhone 12 (mobile) • 722C6A4C-3FCA-4FC6-9D30-9702A0E784B8 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-1 (simulator) • Web Server (web) • web-server • web-javascript • Flutter Tools • Chrome (web) • chrome • web-javascript • Google Chrome 86.0.4240.80 • No issues found!flutter doctor -v
[✓] Flutter (Channel master, 1.24.0-2.0.pre.111, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-GB) • Flutter version 1.24.0-2.0.pre.111 at /Users/tahatesser/Code/flutter_master • Framework revision fe189baf34 (10 hours ago), 2020-10-21 22:25:53 -0400 • Engine revision f459a86610 • Dart version 2.11.0 (build 2.11.0-242.0.dev) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/tahatesser/Code/sdk • Platform android-30, build-tools 30.0.2 • ANDROID_HOME = /Users/tahatesser/Code/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 12.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.1, Build version 12A7403 • CocoaPods version 1.10.0.rc.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] VS Code (version 1.50.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.15.1 [✓] Connected device (5 available) • Taha’s iPhone (mobile) • 00008020-001059882212002E • ios • iOS 14.1 • iPhone 12 (mobile) • 722C6A4C-3FCA-4FC6-9D30-9702A0E784B8 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-1 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.7 19H2 darwin-x64 • Web Server (web) • web-server • web-javascript • Flutter Tools • Chrome (web) • chrome • web-javascript • Google Chrome 86.0.4240.80 • No issues found!jmagman commentedon Oct 22, 2020
@TahaTesser Your logs show:
If you run without
-vit might be more obvious.TahaTesser commentedon Oct 22, 2020
@jmagman
oops, I was expecting them at the end of the logs, silly me
jmagman commentedon Oct 22, 2020
@TahaTesser Yeah ideally it would buffer those pre-VM (dart) logs and show them right before. Feel free to file an issue to improve this experience.
matthewjs commentedon Mar 9, 2021
This still does not work as of flutter 2. The os_log statements show up in flutter logs, but not in the flutter console. Any ideas?
jmagman commentedon Mar 9, 2021
Can you be more specific? What does that mean? Filing a new bug and completely filling out the template is your best bet.
matthewjsummers commentedon Mar 9, 2021
When running flutter in debug on iOS simulator via
flutter run, any os_log statements executed natively from swift do not show up in the flutter console when debugging.When running
flutter logsthese statements do show up, but not in the console. Running on an android simulator is fine as it appears logcat output is directed to the console.An happy to file a bug if required, I just thought it might be quicker to add to this existing issue in case there was something I’m not doing correctly.
jmagman commentedon Mar 9, 2021
@matthewjsummers What do you mean by "console"? The output in terminal when you
flutter run? Or in an IDE session?flutter runin terminal should be showing the output from an attachedlldbdebugging session, so should includeos_logoutput.flutter logdoesn't have an attached debugging session, but is getting those logs from the VM service. So I would actually expect the opposite of what you described.File a new bug, I want to take a look! Please completely fill lout the template, and include a
flutter runoutput with the--verboseflag (it's large, you may need to attach it).point-source commentedon Jun 4, 2021
I also have not been able to get any output from swift print/NSLog. @matthewjsummers did you ever file a new report? If so, where is it?
The only related issue I can find is #69103 but the issue I'm having is that nothing prints.
jmagman commentedon Jun 5, 2021
@point-source Can you file a new issue with the requested info?
github-actions commentedon Jul 31, 2021
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 bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.