io.MultiWriter gotcha! 
       =======================
       
       
       
       
 (TXT) Goofy gopher (.svg) 
       
       The issue 
       ----------
       
       
       I ran into a problem where no logging was being written to a file. 
       
       
       The problematic code was this: 
       
       
       This construct is used to log to a file and for convenience to os.Stdout as well. 
       
       
       At first glance it seems nothing wrong with it. However, reading the docs for io.MultiWriter carefully, it says: 
       
 (HTM) io.MultiWriter 
       
       Each write is written to each listed writer, one at a time. If a listed writer returns an error, that overall write operation stops and returns the error; it does not continue down the list. 
       
       
       So what’s going on? Why would writing to STDOUT return an error? There can be several reasons, but mine was using github.com/kardianos/service (awesome!) to run the application at startup. 
       
 (HTM) github.com/kardianos/service 
       
       The point is - when running as a service - there is no os.Stdout because services are not interactive (in short). 
       
       
       There you have it :-) 
       
       
       The solution 
       -------------
       
       
       This was easily remedied by reversing the order of arguments to MultiWriter . 
       
       
       But what if writing to a file fails? Next up! 
       
       
       Lessons learned 
       ----------------
       
       
       Do not assume STDOUT is available and RTFM . 
       
 (DIR) next Running Go tests in VSCode with CGO
       
       
       Related 
       --------
       
 (DIR) snor
 (TXT) Moustache (.svg) 
 (DIR) Faddy webserver
 (TXT) /img/fallback.svg (.svg) 
 (DIR) Running Go tests in VSCode with CGO
 (TXT) Goofy gopher (.svg) 
 (DIR) shakehands
 (IMG) shakehands (.png) 
 (DIR) Overriding methods in Golang
 (TXT) Goofy gopher (.svg) 
 (DIR) GoTris
 (IMG) GoTris (.png)