SourceHorizon/logger

Long text support

Lzyct opened this issue · 5 comments

Lzyct commented

Hi, I have an issue when trying to log long text like the JWT token

image

For the first line from the logger
and the second line is from log dart:developer

Hi, thanks for reporting this.

Currently, we are using the print function in our ConsoleOutput and AFAIK dart:developer.log doesn't print in production and only accepts a string as message.

As this is a Dart package not a Flutter package, we also can't use Flutter exclusive functions like debugPrint which would circumvent the truncated logs problem as explained here:
flutter/flutter#22665 (comment)
https://docs.flutter.dev/testing/code-debugging#logging

However, despite all of this, you can still create your own LogOutput which uses log and use this in your logger instance.
We could also provide such a LogOutput which uses log, but I wouldn't want to make it the default.

@Bungeefan
debugPrint still truncates the log output. The only way I could find to avoid the truncation is to use the dart:developer package log function.

import 'dart:developer' as developer;
developer.log('---TOKEN--- ${oauth2Client.credentials.accessToken} ---TOKEN---', name: 'my.app.debugCategory');

Isn't there an easier solution? Library could simply add new line every lineLength to the text to ensure it fits within the fixed width. I have line length set to 70 and my messages are around 100 - 150 characters.

@FluffyDiscord Not really. AFAIK, the problem isn't the line length, it's the overall length of the message.

Adding a simple line splitter wouldn't solve the problem either. This would just result in even more log lines, which in turn are still at risk of being dropped by the mobile OS just now without any signs of truncation (e.g. ellipsis).
Different method, same result.
Source: debugPrintThrottled (the default implementation behind debugPrint)

And if this is still desired, it can be implemented on the user side of the library as well.