Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print() statements in Flutter are truncated in flutter run output #22665

Open
DanTup opened this issue Oct 4, 2018 · 23 comments
Open

print() statements in Flutter are truncated in flutter run output #22665

DanTup opened this issue Oct 4, 2018 · 23 comments

Comments

@DanTup
Copy link
Contributor

@DanTup DanTup commented Oct 4, 2018

Originally raised at Dart-Code/Dart-Code#1223 by @rajeshzmoke. If you print() a long string in Flutter, it gets truncated with <…> in the flutter run output:

void main() {
  print('a' * 100 + 'b' * 100 + 'c' * 100 + 'd' * 100 + 'e' * 100 + 'f' * 100 +
      'g' * 100 + 'h' * 100 + 'i' * 100 + 'j' * 100 + 'k' * 100);
  runApp(const GalleryApp());
}

screen shot 2018-10-04 at 10 55 44 am

I'm using the iOS Simulator - it's possible this is a limitation of how we're reading the logs from the device, I'm not sure.

@iozozturk

This comment has been minimized.

Copy link

@iozozturk iozozturk commented Dec 1, 2018

This took my hours to debug, because I was relying on logs and copying access token from there. I was using new experimental log window in Android Studio flutter plugin. No <..> truncation indication there sadly, so didn't realize truncation going on.

@trevorwang

This comment has been minimized.

Copy link
Contributor

@trevorwang trevorwang commented Dec 21, 2018

@iozozturk

I have met the same issue. I was trying to print access_token from oauth, but it's trunked. The iPhone X simulator was being used.

eyJ0eXAiOiJKV1QiLCJub25jZSI6IkFRQUJBQUFBQUFDNXVuYTBFVUZnVElGOEVsYXh0V2pUNk85Wmd4ZkE5dEo0MjdvWkdmc3hWUkJhMXNnNlNGOGwtVktMTGlxVHRYQTVGX0VpQWdBZkwzRzlybFl0c05IQTBiSUR1ZERESk43bVlNU284cHU0TFNBQSIsImFsZyI6IlJTMjU2IiwieDV0IjoibmJDd1cxMXczWGtCLXhVYVh3S1JTTGpNSEdRIiwia2lkIjoibmJDd1cxMXczWGtCLXhVYVh3S1JTTGpNSEdRIn0.eyJhdWQiOiJodHRwczovL2dyYXBoLm1pY3Jvc29mdC5jb20vIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvNzU3YzdmNGItNjQyNy00M2Y4LWI3Y2EtZTQ5NmQ1OTVjZjJhLyIsImlhdCI6MTU0NTM1NjcwOSwibmJmIjoxNTQ1MzU2NzA5LCJleHAiOjE1NDUzNjA2MDksImFjY3QiOjAsImFjciI6IjEiLCJhaW8iOiI0MlJnWUhDZDA5c3RrYUN4ZGZmN2xld2JBNlBxRkpzSzN4M1paN2ZzbkJESDhjWW5KajhCIiwiYW1yIjpbInB3ZCJdLCJhcHBfZGlzcGxheW5hbWUiOiJBcHBDZW50ZXIiLCJhcHBpZCI6IjIxOGZlZmYyLWI5ZWItNGUxYi04Y2U5LTc0NzcyZGZhYzQwYiIsImFwcGlkYWNyIjoiMCIsImZhbWlseV9uYW1lIjoiVHJldm9yIiwiZ2l2ZW5fbmFtZSI6IldhbmciLCJpcGFkZHIiOiIyMDIuNjQuNTMuOTAiLCJuYW1lIjoiVHJldm9yIFdhbmciLCJvaWQiOiI5ZmMwMWE5MS05YzQyLTQ2OTEtOTNlMy1mMDNhZTc1MTE5NTMiLCJwbGF0ZiI6IjIiLCJwdWlkIjoiMTAwM0JGRkRBQkZCNzhGQiIsInNj<…>
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.6 17G4015, locale en-CN)
    • Flutter version 1.0.0 at /Users/xxxx/Dev/flutter/contribution/flutter
    • Framework revision 5391447fae (3 weeks ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/xxxx/Dev/Android/sdk
    • Android NDK at /Users/xxxx/Dev/Android/sdk/ndk-bundle
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/xxxx/Dev/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 1.9.4
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] VS Code (version 1.30.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.21.1

[✓] Connected device (2 available)
    • Android SDK built for x86 • emulator-5554                        • android-x86 • Android 4.4.2 (API 19) (emulator)
    • iPhone X                  • B7435AC0-56E2-4DCC-88C9-85E97326097E • ios         • iOS 12.1 (simulator)
@SachinGanesh

This comment has been minimized.

Copy link

@SachinGanesh SachinGanesh commented Jan 1, 2019

You can use debugPrint instead of print to log long text
https://flutter.io/debugging/#print-and-debugprint-with-flutter-logs
https://stackoverflow.com/a/49156942/8059845

@trevorwang

This comment has been minimized.

Copy link
Contributor

@trevorwang trevorwang commented Jan 8, 2019

@SachinGanesh I used debugPrint also, but it doesn't work.

@aaronfg

This comment has been minimized.

Copy link

@aaronfg aaronfg commented Jan 16, 2019

Having this exact issue. I've resorted to a janky overlayed TextField that I can toggle on that mirrors the log output and is text-selectable.

Really annoying.

@andrewackerman

This comment has been minimized.

Copy link

@andrewackerman andrewackerman commented Jan 23, 2019

Can confirm that both print and debugPrint truncate console output when testing on an iOS device.

@Suraj-Tiwari

This comment has been minimized.

Copy link

@Suraj-Tiwari Suraj-Tiwari commented Jan 27, 2019

@trevorwang
This could be the dirtiest workaround in the history of mankind but it works.
what i did is first
print(auth.idToken.toString());
in this way you'll get truncated string. copy it and write somewhere.

then replace first statement with this
print(auth.idToken.replaceAll(previousTruncatedString, "")toString());
with this you'll get rest of the string

@trevorwang

This comment has been minimized.

Copy link
Contributor

@trevorwang trevorwang commented Jan 28, 2019

@Suraj-Tiwari Thanks. will have a try.

@DanTup

This comment has been minimized.

Copy link
Contributor Author

@DanTup DanTup commented Jan 28, 2019

This could be the dirtiest workaround in the history of mankind but it works.

A slightly nicer workaround might be to create your own print that splits into smaller chunks, then you don't need to modify the code for each long string. Eg.:

void printWrapped(String text) {
  final pattern = new RegExp('.{1,800}'); // 800 is the size of each chunk
  pattern.allMatches(text).forEach((match) => print(match.group(0)));
}

(note: I haven't battle-tested that function but it worked in a quick test..).

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Feb 3, 2019

I had a very long json string to be printed out but in the console i saw a single string truncated so i used this method (if can be helpful for someone):

JsonEncoder encoder = new JsonEncoder.withIndent('  ');
String prettyprint = encoder.convert(yourJsonString);
debugPrint(prettyprint);

But it works only with json strings, i have not idea about how to do with "normal" strings.
The first thing i think is to add manually a \n after every n characters , for now, while waiting for a stable fix!

@namiwang

This comment was marked as outdated.

Copy link

@namiwang namiwang commented Feb 28, 2019

Confirmed here.

I printed and copied a JWT from the console and wasted a few hours in debugging.

At least a trailing ellipsis "…" would be nice.

@markathomas

This comment has been minimized.

Copy link

@markathomas markathomas commented Mar 27, 2019

Same issue here. I have noticed a 1024 character limit in the console.

@ngprnk

This comment has been minimized.

Copy link

@ngprnk ngprnk commented May 8, 2019

any fixes for this issue yet ?

@Suraj-Tiwari

This comment has been minimized.

Copy link

@Suraj-Tiwari Suraj-Tiwari commented May 8, 2019

@ineelp

This comment has been minimized.

Copy link

@ineelp ineelp commented May 8, 2019

I checked with full access token length and after printing it. There is a huge difference in size.

@chenenyu

This comment has been minimized.

Copy link

@chenenyu chenenyu commented May 27, 2019

plz fix this issue.

@andrewackerman

This comment has been minimized.

Copy link

@andrewackerman andrewackerman commented May 27, 2019

So as it turns out, this isn't a bug in Flutter. It seems like this is a hard limitation set by the mobile platforms themselves. For iOS, there doesn't seem to be any kind of configuration for it but it does have a (very) dirty fix:

https://stackoverflow.com/questions/39584707/nslog-on-devices-in-ios-10-xcode-8-seems-to-truncate-why

For Android, there doesn't seem to be any fix. Only the workaround of the kind like DanTup mentioned:

https://stackoverflow.com/questions/8888654/android-set-max-length-of-logcat-messages

@jesobremonte

This comment has been minimized.

Copy link

@jesobremonte jesobremonte commented Jun 28, 2019

There is a second optional parameter in debugPrint you can use to wrap the log text:

debugPrint(someSuperLongString, wrapWidth: 1024);
@Akshar-Patel

This comment has been minimized.

Copy link

@Akshar-Patel Akshar-Patel commented Jul 20, 2019

This could be the dirtiest workaround in the history of mankind but it works.

A slightly nicer workaround might be to create your own print that splits into smaller chunks, then you don't need to modify the code for each long string. Eg.:

void printWrapped(String text) {
  final pattern = new RegExp('.{1,800}'); // 800 is the size of each chunk
  pattern.allMatches(text).forEach((match) => print(match.group(0)));
}

(note: I haven't battle-tested that function but it worked in a quick test..).

This is the only workaround that can work easily right now. Thanks @DanTup

@lionnner

This comment has been minimized.

Copy link

@lionnner lionnner commented Aug 29, 2019

when to fix it? so long time...

@Furtim

This comment has been minimized.

Copy link

@Furtim Furtim commented Sep 18, 2019

There is a second optional parameter in debugPrint you can use to wrap the log text:

debugPrint(someSuperLongString, wrapWidth: 1024);

This works perfectly. I set it to 1000 rather than 1024 to give some headroom as I wasn't clear whether the 'flutter:' prefix counted in the total, but it splits the message into multiple lines and everything is shown.

Spot on!

@andrewackerman

This comment has been minimized.

Copy link

@andrewackerman andrewackerman commented Sep 18, 2019

Can this issue be locked? It's become an endless cycle of people either requesting an update or posting the same fix/workaround.

@MuhammadAliKhan1

This comment has been minimized.

Copy link

@MuhammadAliKhan1 MuhammadAliKhan1 commented Oct 3, 2019

Any updates on print()? Having the same problem.

@jmagman jmagman added this to Awaiting triage in Tools - command line usability review via automation Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
You can’t perform that action at this time.