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

very long strings are not fully printed ( they are truncated ) #60

Open
nateshmbhat opened this issue Sep 6, 2020 · 13 comments
Open

very long strings are not fully printed ( they are truncated ) #60

nateshmbhat opened this issue Sep 6, 2020 · 13 comments

Comments

@nateshmbhat
Copy link

Since you are using "print" function in the console printer , it's not fully printing the entire contents of a string.

Dart provides a "log" function from the "dart:developer" package which properly prints the full contents.

i think we should change the print function to the log function. .

@nateshmbhat
Copy link
Author

any updates on this @leisim @haarts ?

@haarts
Copy link
Collaborator

haarts commented Sep 17, 2020

No. There's a period coming in which I can ponder these questions. For one I need to think about the implications of adding a dependency. And the impact of that dependency on all platforms.

@trongdth
Copy link

@nateshmbhat you can use my temporary repo as a quick solution https://github.com/trongdth/logger/tree/full_print but I would recommend to wait for author.

@nateshmbhat
Copy link
Author

nateshmbhat commented Sep 22, 2020

No. There's a period coming in which I can ponder these questions. For one I need to think about the implications of adding a dependency. And the impact of that dependency on all platforms.

The dependency I'm talking about is "dart:developer" which is built in dart language itself.

So I'm pretty sure it won't affect in a negative way

@haarts
Copy link
Collaborator

haarts commented Sep 28, 2020

I've taking some time to muck around with this and I found that dart:developer solution did not work for me. I replaced the print statement in ConsoleOutput with log and it didn't output anything. Twiddled around with the level named argument but that yielded no results.

The truncation of log lines is because of (Android only?) platform limitations. I believe this to be the offensive line.

I've also looked into debugPrint but that only works for Flutter.

That leaves us with writing an own solution a la Timber.

I believe something like this should/could do the trick.

@haarts haarts closed this as completed Sep 28, 2020
@haarts haarts reopened this Sep 28, 2020
@haarts
Copy link
Collaborator

haarts commented Sep 28, 2020

Even more digging. Would could copy the heart of the debugPrint function from Flutter. It is found here. It is long...

@DominicOrga
Copy link

DominicOrga commented Nov 5, 2020

I don't know if this is the best solution, but I was able to circumvent this issue by updating the ConsoleOutput to:

class ConsoleOutput extends LogOutput {
  @override
  void output(OutputEvent event) {
    event.lines.forEach(printWrapped);
  }

  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)));
  }

  // This works too.
  void printWrapped2(String text) => debugPrint(text, wrapWidth: 1024);
}

I took the solution from here.

@comatory
Copy link

I'm running into this problem as well. I serialize JSONs into string (using JsonEncoder.withIndent) and then passing that to logger.

Obviously these formatted strings can get large quickly and the output is trimmed. This issue goes away when I use PrettyPrinter.

Still this seems like a rather limitation that I would not expect. Could you improve the package somehow or at least provide a way to remove the limitation via configuration?

@comatory
Copy link

comatory commented Oct 8, 2021

Any news on this?

@Isuru-Nanayakkara
Copy link

@comatory Hi, how did you get the JSON string to print fully? I tried this and it still truncates the string.

var j = json.encoder.convert(body);
var logger = Logger(filter: null, printer: PrettyPrinter(), output: null);
logger.d(j);

@comatory
Copy link

@Isuru-Nanayakkara I'm not sure it seemed by just using PrettyPrinter, it worked.

However in the end I went with @DominicOrga solution. It would be great if this could get fixed by mimicking Flutter's print function.

@manuel-plavsic
Copy link

manuel-plavsic commented May 29, 2022

Hello guys. Very recently I discovered this library, and this afternoon I encountered the same problem. Luckily, I discovered a workaround.

Idea: It is not possible to print a whole line, e.g., a json string without indentation, because at some point it gets truncated. However, it is possible to print multiple lines, e.g., a json with indentation.

So, thanks to this answer, it is possible to deserialize the json and then serialize it again, with indent (and log it). Alternatively, you may want to ensure the json strings already are indented in order to avoid the "extra serialization with indent".

IMO, the logs are also much clearer if the information in the json string is properly indented.

@wiktoriasobczyk
Copy link

You can create custom output for this purpose and thanks to that printer should print longer messages :)

///Allows parsing longer strings than 1024 chars
class Output extends LogOutput {
  @override
  void output(OutputEvent event) {
    log(event.lines.join(""));
  }
}

and use it as a custom LogOutput :D

Example class


class LoggerReporter extends Logger {
  /// Class name that invokes the logger
  final String source;

  LoggerReporter(
    this.source,
  ) : super(printer: LoggerPrinter(source), output: Output());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants