expecto icon indicating copy to clipboard operation
expecto copied to clipboard

[Logging] PR back ANSI logger

Open haf opened this issue 7 years ago • 2 comments

To Logary Facade to be used elsewhere.

Checklist

  • [x] Extract ANSIOutputWriter from Process
  • [x] Invert calls from AOW to Process, to avoid a dependency on Process from Logging.fs
  • [x] Test the refactoring, released Expecto 8.6.0
  • [ ] Refactor the code in AOW to use Logary Facade's Global state object, make global overrides explicit rather than implicit in loading the code

haf avatar Jul 23 '18 11:07 haf

https://github.com/haf/expecto/blob/57489567c10849f1d4db05312864f4be01fdb503/Expecto/Expecto.fs#L1798 is bugged

Since it's mutated on running the tests, it causes things printed before the tests to have no colour

image

haf avatar Nov 17 '18 11:11 haf

The ANSI Console Writer can't be used in more than a single place in a process, because it has side-effects... The refactoring done 1bb391c is good, but only a small step towards completing this PR; this code needs to be coordinated between loggers/Facades.

    // since this executes on module load, it will be the original stdout
    stdout.Flush()
    let encoding = stdout.Encoding
    let std s = prettyPrint true true [s, foregroundColor]

    Console.SetOut (new FuncTextWriter(encoding, std))
    let errorEncoding = stderr.Encoding
    let errorToOutput s = prettyPrint true true [s, ConsoleColor.Red]

    Console.SetError (new FuncTextWriter(errorEncoding, errorToOutput))

haf avatar Nov 17 '18 18:11 haf