very long strings are not fully printed ( they are truncated )
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. .
any updates on this @leisim @haarts ?
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.
@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.
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
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.
Even more digging. Would could copy the heart of the debugPrint function from Flutter. It is found here. It is long...
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.
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?
Any news on this?
@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);
@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.
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.
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());
}