haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
663 stars 96 forks source link

No clear path to set a custom logger #432

Open ImaginaryDevelopment opened 2 years ago

ImaginaryDevelopment commented 2 years ago

Maybe I'm just not having luck following the source code, but it appears to me that logging is service-located at https://github.com/haf/expecto/blob/main/Expecto/Expecto.Impl.fs#L15

I see no clear way to inject Serilog or any other LogProvider. The only example given in documentation appears to show how to get Logary to log into the Expecto logger, without anyway to hook up a custom logger for Expecto to use.

The motivating case might be simple enough to solve, I have dotnet watch test running, which appears to by default, print every single skipped test. I have over 400 tests, and I'm trying to REPL write a new section of 4 tests. so I put in ftestlist and proceed. Each change I make I get ~10 lines of errors somewhere in the spam of 400 lines letting me know the name of every single test it skipped.

However I'd like to be able to solve the larger case of being able to hook a different log provider into Expecto.

jwosty commented 11 months ago

It looks like Logary's adapter uses some reflection magic to pull this off: https://github.com/causiq/logary/blob/master/src/adapters/Logary.Adapters.Facade/Logary.Adapters.Facade.fs

I imagine it's hypothetically possible to write a different adapter that plugs into something else (i.e. Microsoft.Extensions.Logging), but that's probably easier said than done...

EDIT: Logger is an abstract class; there should be a way to provide your own implementation/adapter: https://github.com/haf/expecto/blob/2cb90ee2afe7bc8b7f71a95a9e4776ec600f9b40/Expecto/Logging.fs#L195