I have the following code:
package main
import(
"log"
"os"
)
type LogFilter struct {}
func (t *LogFilter) Write(p []byte) (int, error) {
_ = log.Flags()
return os.Stderr.Write(p)
}
func main() {
log.SetOutput(&LogFilter{})
log.Println("Hello, playground")
}
Which Deadlocks because of http://golang.org/src/pkg/log/log.go line 135 defers the lock until after the write. Which in the write I'm calling Flags which tried to get the lock.
Is there any reason that they (Write & Flags) should share the same mutex?