logger icon indicating copy to clipboard operation
logger copied to clipboard

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

Open nateshmbhat opened this issue 5 years ago • 13 comments

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 avatar Sep 06 '20 06:09 nateshmbhat

any updates on this @leisim @haarts ?

nateshmbhat avatar Sep 17 '20 04:09 nateshmbhat

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.

haarts avatar Sep 17 '20 06:09 haarts

@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.

trongdth avatar Sep 22 '20 03:09 trongdth

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

nateshmbhat avatar Sep 22 '20 04:09 nateshmbhat

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 avatar Sep 28 '20 08:09 haarts

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

haarts avatar Sep 28 '20 08:09 haarts

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.

DominicOrga avatar Nov 05 '20 02:11 DominicOrga

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 avatar Sep 15 '21 08:09 comatory

Any news on this?

comatory avatar Oct 08 '21 07:10 comatory

@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 avatar Nov 20 '21 03:11 Isuru-Nanayakkara

@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.

comatory avatar Nov 20 '21 06:11 comatory

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.

manuel-plavsic avatar May 29 '22 16:05 manuel-plavsic

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

wiktoriagrochowalska avatar Feb 21 '23 15:02 wiktoriagrochowalska