flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.97k stars 27.18k forks source link

GoRouter have duplicated logs #143704

Closed waliseddiqi closed 6 months ago

waliseddiqi commented 7 months ago

Steps to reproduce

by using the latest go router version with latest logging package version can be reproduced as below

logging package : https://pub.dev/packages/logging

  1. set debugLogDiagnostics: true in GoRouter
  2. have the configuration below for Logging in code sample section

Also with version go_router: ^10.2.0 and below the logs seems like working fine and shows with debugLogDiagnostics: false to false

flutter:3.16.5 go_router:13.1.0 logginer:1.2.0

Expected results

Expected logs

D/[FBP-Android](19236): [FBP] onMethodCall: getAdapterState
I/flutter (19236): 2024-02-19 15:39:22.060845 INFO - GoRouter: Full paths for routes:
I/flutter (19236):   => /home
I/flutter (19236):   => /drip
I/flutter (19236): 
I/flutter (19236): 2024-02-19 15:39:22.073715 INFO - GoRouter: setting initial location /home
I/flutter (19236): 2024-02-19 15:39:22.370618 INFO - GoRouter: Using MaterialApp configuration
I/flutter (19236): 2024-02-19 15:39:22.533719 FINE - HomeViewModel: init HomeViewModel
I/flutter (19236): 2024-02-19 15:39:22.650645 FINE - HomeViewModel: Emitted state ViewStateLoading()

Actual results

Duplicated logs after setting debugLogDiagnostics: true

I/flutter (19236): 2024-02-19 15:39:22.060845 INFO - GoRouter: Full paths for routes:
I/flutter (19236):   => /home
I/flutter (19236):   => /drip
I/flutter (19236): 
[GoRouter] Full paths for routes:
             => /home
             => /drip
I/flutter (19236): 2024-02-19 15:39:22.073715 INFO - GoRouter: setting initial location /home
[GoRouter] setting initial location /home
I/flutter (19236): 2024-02-19 15:39:22.370618 INFO - GoRouter: Using MaterialApp configuration
2
[GoRouter] Using MaterialApp configuration
I/flutter (19236): 2024-02-19 15:39:22.521964 INFO - GoRouter: Using MaterialApp configuration
[HomeViewModel] init HomeViewModel
I/flutter (19236): 2024-02-19 15:39:22.533719 FINE - HomeViewModel: init HomeViewModel
I/flutter (19236): 2024-02-19 15:39:22.650645 FINE - HomeViewModel: Emitted state ViewStateLoading()
[HomeViewModel] Emitted state ViewStateLoading()

Code sample

Code sample ``` import 'dart:async'; import 'package:equatable/equatable.dart'; import 'package:logging/logging.dart'; import 'plain_log_writer.dart'; class LogConfig { static StreamSubscription? loggerSubscription; static void init({required Level logLevel}) { final PlainStdoutLogWriter logWriter = PlainStdoutLogWriter(); Logger.root.level = logLevel; loggerSubscription?.cancel(); loggerSubscription = Logger.root.onRecord.listen((LogRecord record) { if (record.error is Error) { logWriter.logError(record, record.error as Error); } else if (record.error is Exception) { logWriter.logException(record, record.error as Exception); } else if (record.stackTrace != null) { logWriter.logStacktrace(record, record.stackTrace!); } else { logWriter.logRecord(record); } }); // use generated (by equatable) toString methods for logging out objects EquatableConfig.stringify = true; Logger.root.info('Started logging on level ${Logger.root.level} with $logWriter'); } } ``` and ``` import 'package:flutter/foundation.dart'; import 'package:logging/logging.dart'; class PlainStdoutLogWriter { void logError(LogRecord record, Error error) { _printLog(record, ': $error\n${error.stackTrace}'); } void logException(LogRecord record, Exception exception) { _printLog(record, ': $exception\n${record.stackTrace ?? ""}'); } void logStacktrace(LogRecord record, StackTrace stackTrace) { _printLog(record, ': ${record.error}\n${record.stackTrace ?? "null stackTrace"}'); } void logRecord(LogRecord record) { _printLog(record); } void _printLog(LogRecord record, [String extraMessage = '']) { // don't log if turned off if (record.level < Level.OFF) { // Here it is ok to print(), we are using the logger until here. // ignore: avoid_print debugPrint('${record.time} ${record.level.name} - ${record.loggerName}: ${record.message}$extraMessage'); } } } ``` also by setting the log level to any not above `INFO` ` LogConfig.init(logLevel: Level.FINE);`

Screenshots or Video

Also duplicated logs shows as yellow color in VScode

Screenshot 2024-02-19 at 15 45 55

Flutter Doctor output

[!] Flutter (Channel [user-branch], 3.16.5, on macOS 14.3 23D56 darwin-arm64, locale en-DE) ! Flutter version 3.16.5 on channel [user-branch] at /Users/**/Development/flutter Currently on an unknown channel. Run flutter channel to switch to an official channel. If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install. ! Upstream repository unknown source is not a standard remote. Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error. • Framework revision 78666c8dc5 (9 weeks ago), 2023-12-19 16:14:14 -0800 • Engine revision 3f3e560236 • Dart version 3.2.3 • DevTools version 2.28.4 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at /Users/**/Library/Android/sdk ✗ cmdline-tools component is missing Run path/to/sdkmanager --install "cmdline-tools;latest" See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run flutter doctor --android-licenses to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[!] Xcode - develop for iOS and macOS (Xcode 15.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15C500b ✗ Unable to get list of installed Simulator runtimes. • CocoaPods version 1.14.3

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2023.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.79.2) • VS Code at /Users/**/Downloads/Visual Studio Code.app/Contents • Flutter extension version 3.82.0

[✓] Connected device (3 available) • 2201123G (mobile) • 7b5a8447 • android-arm64 • Android 13 (API 33) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.3 23D56 darwin-arm64

[✓] Network resources • All expected network resources are available.

! Doctor found issues in 4 categories.

darshankawar commented 7 months ago

@waliseddiqi Most probably you are hitting https://github.com/flutter/flutter/issues/107982 that you can check and confirm. Also, this could be occuring due to the fact that you are passing debugLogDiagnostics: true. Can you try by passing it as false and check if log is duplicated still ? Moreover, check this and other underlying comments from the linked issue to see if they help to get expected result or not.

Please check above using latest go_router version.

waliseddiqi commented 7 months ago

@darshankawar I checked the issue you mentioned before and it didnt help resolving the issue I am facing. Passing debugLogDiagnostics: false gets rid of the duplicated logs but It doesnt show go_router logs anymore, the change was added here for disabling go_router logs if the flag is false.

I just want to see go_router logs without having duplicated logs of my app as I added in screenshot. I guess the issue occurs when my app and go_router listens to logs at same time.

darshankawar commented 7 months ago

@waliseddiqi Check this and the solution to see if it helps to resolve your issue or not.

waliseddiqi commented 6 months ago

@darshankawar those are the exact issue I am facing right now. Hopefully the request changes in there will be merged in upcoming go_router updates. I will follow the thread there you may close this issue or mention it there

darshankawar commented 6 months ago

Thanks for confirming. Closing this as duplicate. You may share your findings in that issue for better tracking.

github-actions[bot] commented 6 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.