SourceHorizon / logger

Small, easy to use and extensible logger which prints beautiful logs.
https://pub.dev/packages/logger
MIT License
197 stars 33 forks source link

Long text support #25

Closed Lzyct closed 9 months ago

Lzyct commented 1 year ago

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

Bungeefan commented 1 year ago

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: https://github.com/flutter/flutter/issues/22665#issuecomment-506687219 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.

MeltdownInteractive commented 9 months ago

@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');
FluffyDiscord commented 9 months ago

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.

Bungeefan commented 9 months ago

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