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

Long text support #25

Closed
Lzyct opened this issue May 21, 2023 · 5 comments
Closed

Long text support #25

Lzyct opened this issue May 21, 2023 · 5 comments
Labels
flutter Specific to Flutter

Comments

@Lzyct
Copy link

Lzyct commented May 21, 2023

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 Bungeefan added the flutter Specific to Flutter label May 22, 2023
@Bungeefan
Copy link
Member

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.

@MeltdownInteractive
Copy link

@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
Copy link

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
Copy link
Member

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

@littleantfly
Copy link

littleantfly commented Sep 26, 2024

I rewrote the component's ConsoleOutput and used developer.log instead of print to solve the problem. I hope it can help you.

import 'package:logger/logger.dart';
import 'dart:developer' as developer;

var logger = Logger(
  filter: AppConfig.DEBUG ? DevelopmentFilter() : ProductionFilter(),
  printer: PrettyPrinter(methodCount: 0, errorMethodCount: 30, colors: true),
  output: MyConsoleOutput(),
);

class MyConsoleOutput extends ConsoleOutput {
  @override
  void output(OutputEvent event) {
    event.lines.forEach(developer.log);
  }
}

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

No branches or pull requests

5 participants