The io.Writer is too low level to be useful. Imagine a logger that wants to send an sms on severe errors only.
The best solution is to declare your own logger interface - but similar to the collections discussion it would better if the stdlib declared an ILogger interface (or similar) > On Aug 31, 2021, at 3:48 AM, Rupert Paddington <blm...@gmail.com> wrote: > > If Logger was an interface it would be pretty large and to some extent > application-specific, which is undesirable. > > Instead inject the sink (io.Writer). > > This is preferable in every way: > > * the interface is small and universal > * it eliminates the coupling with any specific library present and future > * it requires to test the behaviour instead of the collaboration > > These are the same principles why for example the http.Handler interface > takes an http.ResponseWriter, and then the outcome of the response can be > tested by reading from the writer that is passed at testing time. >> On Tuesday, 31 August 2021 at 03:19:29 UTC+1 amits...@gmail.com wrote: >> On Tue, Aug 31, 2021 at 8:58 AM Kevin Chowski <ke...@chowski.com> wrote: >> >> <snip> >> >> >> > To the original poster: can you just declare your own Logger-like >> > interface and allow users of your library to pass whatever logging >> > implementation they have? In what ways are you thinking that you're forced >> > to be coupled with the standard library's implementation? >> >> Yes, I can do that - that's a good idea actually - although more >> complicated than one I would have liked for my use-case (more on this >> in my original post and below), but certainly a feasible one with long >> term benefits. >> >> > In what ways are you thinking that you're forced to be coupled with the >> > standard library's implementation? >> >> When I first add some logging to my application, I am doing it using >> the standard library's log.Printf(), log.Println(), log.Fatal() and >> friends. Now, I reach a point of time where I want to start structured >> logging but i want to do it incrementally. My existing Printf(), >> Println() calls should continue to build. The only change I want to do >> initially is simply change how I am constructing the log.Logger >> object. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/c76931fb-4d7e-40f2-84d3-8923dd280748n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/874D83D2-6CF1-405A-B500-1399DB77785A%40ix.netcom.com.