simc / logger

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

Add Switches to no color when running for CI so that console logs can be processed by JUnit test reports #123

Open marcellodesales opened 2 years ago

marcellodesales commented 2 years ago

Problem

NOTE: This was identified in a CI build for Mobile apps using a junit dart formatter https://gitlab.com/gitlab-org/gitlab/-/issues/268035#note_801222659

Possible Solution

Question: How can we use flutter test and format the output of the tests to be without colors?

JUnit converted test report with output with colors

flutter test --coverage --machine | tojunit --output build/app/reports/junit-tests-report.xml
cat output build/app/reports/junit-tests-report.xml
....
....
┌───────────────────────────────────────────────────────────────────────────────
│ #0   UserRepository.saveUserAddress (package:parking_web_app_maicero_shop/infrastructure/user/user_repository.dart:573:17)
│ #1   <asynchronous suspension>
│ #2   StackZoneSpecification._registerUnaryCallback.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 12:51:49.751 (+0:00:03.910572)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ ⛔ Critical server error: Http status error [500] in the function: saveUserAddress() on user_repository
└──────────────────────────────

XML Linter errors with special characters from colored output

$ docker run -i --rm -v $PWD:/data mribeiro/xmllint build/app/reports/junit-tests-report.xml
Unable to find image 'mribeiro/xmllint:latest' locally
latest: Pulling from mribeiro/xmllint
Image docker.io/mribeiro/xmllint:latest uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/
a3ed95caeb02: Pull complete
5f6cc4b8eedc: Pull complete
7ebc7bd59630: Pull complete
Digest: sha256:e8293a7906daf6bba7cc2812e9cc54c0e0932afe6a162987cf999bcfd08c93a2
Status: Downloaded newer image for mribeiro/xmllint:latest
build/app/reports/junit-tests-report.xml:63: parser error : PCDATA invalid Char value 27
┌──────────────────────
^
build/app/reports/junit-tests-report.xml:63: parser error : PCDATA invalid Char value 27
��──────────────────────────
┌──────────────────────
^
build/app/reports/junit-tests-report.xml:63: parser error : PCDATA invalid Char value 27
��──────────────────────────
                                                                               ^
build/app/reports/junit-tests-report.xml:64: parser error : PCDATA invalid Char value 27
│ #0   UserRepository.signUp (package:parking_web_app_maicero_shop/
^
build/app/reports/junit-tests-report.xml:64: parser error : PCDATA invalid Char value 27
ge:parking_web_app_maicero_shop/infrastructure/user/user_repository.dart:178:17)
                                                                               ^
build/app/reports/junit-tests-report.xml:65: parser error : PCDATA invalid Char value 27
│ #1   <asynchronous suspension>
^
build/app/reports/junit-tests-report.xml:65: parser error : PCDATA invalid Char value 27
│ #1   <asynchronous suspension>
                                                ^
build/app/reports/junit-tests-report.xml:66: parser error : PCDATA invalid Char value 27
│ #2   StackZoneSpecification._registerUnaryCallback.<anonymous
^

Requirement

haarts commented 2 years ago

I would not use the PrettyPrinter in this case. You are able to switch formatting via configuration by passing a different Printer based on a env var, cli argument, whatever.