logger icon indicating copy to clipboard operation
logger copied to clipboard

Colors not working on iOS

Open vico-aguado opened this issue 6 years ago • 25 comments

Hi!!

I try in iOS and the log show this:

│ #1   _FutureBuilderState.build (package:flutter/src/widgets/async.dart)
flutter: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄\^[[<…>
flutter: │ 🐛 Log message with 2 methods\^[[<…>
flutter: └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────\^[[<…>
flutter: \^[[38;5;12m┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: \^[[38;5;12m│ 💡 Info message<…>
flutter: \^[[38;5;12m└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: \^[[38;5;208m┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: \^[[38;5;208m│ ⚠️ Just a warning!<…>
flutter: \^[[38;5;208m└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: \^[[38;5;196m┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: \^[[38;5;196m│ \^[[0m\^[[39m\^[[48;5;196mTest Error<…>
flutter: \^[[38;5;196m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…>
flutter: \^[[38;5;196m│ #0   MyPage.build.() (package:_app/src/sections/my_page.dart:55:3<…>
flutter: \^[[38;5;196m│ #1   _FutureBuilderState.build (package:flutter/src/widgets/async.dar<…>
flutter: \^[[38;5;196m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…>
flutter: \^[[38;5;196m│ ⛔ Error! Something bad happened<…>
flutter: \^[[38;5;196m└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: \^[[38;5;199m┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: \^[[38;5;199m│ #0   MyPage.build.() (package:_app/src/sections/my_page.dart:57:3<…>
flutter: \^[[38;5;199m│ #1   _FutureBuilderState.build (package:flutter/src/widgets/async.dar<…>
flutter: \^[[38;5;199m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…>
flutter: \^[[38;5;199m│ 👾 What a terrible failure log<…>
flutter: \^[[38;5;199m└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>

vico-aguado avatar Jun 05 '19 00:06 vico-aguado

Oh no, I didn't try it on iOS yet.

Do you use Xcode or VSCode?

simc avatar Jun 05 '19 00:06 simc

I use both, but more often VSCode

vico-aguado avatar Jun 05 '19 01:06 vico-aguado

And do you see this problem in Xcode or VSCode?

Xcode does not support colors but in VSCode it should work fine.

simc avatar Jun 05 '19 01:06 simc

I see this problem in both :(

vico-aguado avatar Jun 05 '19 01:06 vico-aguado

Okay thank you! I'll test it.

simc avatar Jun 05 '19 01:06 simc

I may take a little longer to fix this problem. In the meantime I added a parameter to the PrettyPrinter to disable colors.

simc avatar Jun 05 '19 18:06 simc

@leisim Any progress on that? Package is really useful, but the output becomes unreadable when debugging on iOS.

priezz avatar Nov 18 '19 13:11 priezz

I don't think XCode supports colors: https://stackoverflow.com/questions/40583721/print-to-console-log-with-color. The mentioned XcodeColors project seems only to work for XCode < 9.x. Your safest best seems to pass the colors=false arg to the constructor.

haarts avatar Dec 04 '19 12:12 haarts

I'm using VSCode and have the same problem...

image

emersonsiega avatar Jan 30 '20 18:01 emersonsiega

Colors will never work in IDE terminals. None support ANSI escape codes. Passing colors: false to the constructor of PrettyPrinter at least gets rid of the garbage.

haarts avatar Jan 31 '20 08:01 haarts

Colors will never work in IDE terminals. None support ANSI escape codes. Passing colors: false to the constructor of PrettyPrinter at least gets rid of the garbage.

That is not completely correct, flutter doctor works with colors in VSCode and IntelliJ. So it seems like some double encoding or escaping is happening.

kuhnroyal avatar Jan 31 '20 13:01 kuhnroyal

I'm not sure why, but on one project the colors work perfectly, but on another, they don't work. I haven't figured out the difference yet.

robrichardson13 avatar May 27 '20 16:05 robrichardson13

Has anyone figured this out?

I went through this article and managed to get colors working in the Debug Console (Vscode MacOS).

Screenshot 2021-07-01 at 15 31 47

Seems the issue is related to bad escaping as suggested by @kuhnroyal.

dav3rin avatar Jul 01 '21 12:07 dav3rin

This seems to be an issue in the flutter library, not logger: https://github.com/flutter/flutter/issues/20663

aliak00 avatar Aug 08 '21 20:08 aliak00

This issue is a bit complex, but we could solve it by changing logger/outputs/console_output.dart to below:

import 'dart:io'; import 'dart:developer' as developer; import 'package:flutter/foundation.dart'; import 'package:idealab/plugins/logger/log_output.dart'; import 'package:idealab/plugins/logger/logger.dart';

const bool _kReleaseMode = kReleaseMode; /// Default implementation of [LogOutput]. /// /// It sends everything to the system console. class ConsoleOutput extends LogOutput { @OverRide void output(OutputEvent event) { if (_kReleaseMode || !Platform.isIOS ) { event.lines.forEach(debugPrint); } else { event.lines.forEach(developer.log); }

} }

yushihang avatar Dec 13 '21 16:12 yushihang

Is there any news on this point? I'd love to have colored outputs using VSCode. Maybe there's a plugin to fix that?

jacobokoenig avatar Apr 21 '22 13:04 jacobokoenig

A plugin in VSCode that would enable ASNI colors would work indeed.

haarts avatar Jun 03 '22 13:06 haarts

This issue is a bit complex, but we could solve it by changing logger/outputs/console_output.dart to below:

import 'dart:io'; import 'dart:developer' as developer; import 'package:flutter/foundation.dart'; import 'package:idealab/plugins/logger/log_output.dart'; import 'package:idealab/plugins/logger/logger.dart';

const bool _kReleaseMode = kReleaseMode; /// Default implementation of [LogOutput]. /// /// It sends everything to the system console. class ConsoleOutput extends LogOutput { @OverRide void output(OutputEvent event) { if (_kReleaseMode || !Platform.isIOS ) { event.lines.forEach(debugPrint); } else { event.lines.forEach(developer.log); }

} }

Nice, This method successfully solves the problem of no color in iOS. You should save this file, and run again, then it will take effect.

Espero1995 avatar Jul 05 '22 02:07 Espero1995

image

flutter: \^[[38;5;12mThis, eg[statusCode]: 200<…>
flutter: \^[[38;5;12mThis, eg[statusMessage]: OK<…>

This is my message output.

strongwill01 avatar Aug 04 '22 02:08 strongwill01

image

flutter: \^[[38;5;12mThis, eg[statusCode]: 200<…>
flutter: \^[[38;5;12mThis, eg[statusMessage]: OK<…>

This is my message output.

same to me

xiaoLit avatar Oct 15 '22 08:10 xiaoLit

This issue is a bit complex, but we could solve it by changing logger/outputs/console_output.dart to below:

import 'dart:io'; import 'dart:developer' as developer; import 'package:flutter/foundation.dart'; import 'package:idealab/plugins/logger/log_output.dart'; import 'package:idealab/plugins/logger/logger.dart';

const bool _kReleaseMode = kReleaseMode; /// Default implementation of [LogOutput]. /// /// It sends everything to the system console. class ConsoleOutput extends LogOutput { @OverRide void output(OutputEvent event) { if (_kReleaseMode || !Platform.isIOS ) { event.lines.forEach(debugPrint); } else { event.lines.forEach(developer.log); }

} }

CleanShot 2022-10-24 at 09 57 06@2x

Thanks it works!!

Thaimay avatar Oct 24 '22 02:10 Thaimay

Thank you. It works 🚀

tanhnv-avnon avatar May 17 '23 14:05 tanhnv-avnon

IMHO, not 100% clear, but you have to create an object of the class ConsoleOutput and assign it to the Logger constructor.

import 'dart:developer' as developer;

import 'package:flutter/foundation.dart';
import 'package:logger/logger.dart';
import 'package:universal_io/io.dart';

Logger logger = Logger(output: ConsoleOutput());

/// Extends 'LogOutput' to correctly display console colors on macOS systems.
///
/// The behavior is determined by the application's run mode (Release or Debug)
/// and the operating platform (iOS or non-iOS).
///
/// For more information, see: https://github.com/simc/logger/issues/1#issuecomment-1582076726
class ConsoleOutput extends LogOutput {
  @override
  void output(OutputEvent event) {
    if (kReleaseMode || !Platform.isIOS) {
      event.lines.forEach(debugPrint);
    } else {
      event.lines.forEach(developer.log);
    }
  }
}

friebetill avatar Jun 08 '23 07:06 friebetill

not sure why but this works, thanks! colors worked on android but not iOS. this fixes the logs on IOS. thanks

IMHO, not 100% clear, but you have to create an object of the class ConsoleOutput and assign it to the Logger constructor.

import 'dart:developer' as developer;

import 'package:flutter/foundation.dart';
import 'package:logger/logger.dart';
import 'package:universal_io/io.dart';

Logger logger = Logger(output: ConsoleOutput());

/// Extends 'LogOutput' to correctly display console colors on macOS systems.
///
/// The behavior is determined by the application's run mode (Release or Debug)
/// and the operating platform (iOS or non-iOS).
///
/// For more information, see: https://github.com/simc/logger/issues/1#issuecomment-1582076726
class ConsoleOutput extends LogOutput {
  @override
  void output(OutputEvent event) {
    if (kReleaseMode || !Platform.isIOS) {
      event.lines.forEach(debugPrint);
    } else {
      event.lines.forEach(developer.log);
    }
  }
}

colbymaloy avatar Sep 14 '23 19:09 colbymaloy