1 // Package logonce implements an io.Writer facade that only performs distinct
2 // writes. This can be used by log.Loggers as they're guaranteed to make a
3 // single Write method call for each message. This is useful for loggers that
4 // print useful information about unexpected conditions that aren't fatal in
14 // A default logger similar to the default logger in the log package.
15 var Stderr *log.Logger
18 // This should emulate the default logger in the log package where
19 // possible. No time flag so that messages don't differ by time. Code
20 // debug information is useful.
21 Stderr = log.New(Writer(os.Stderr), "logonce: ", log.Lshortfile)
26 writes map[string]struct{}
29 func (w writer) Write(p []byte) (n int, err error) {
31 if _, ok := w.writes[s]; ok {
38 w.writes[s] = struct{}{}
42 func Writer(w io.Writer) io.Writer {
45 writes: make(map[string]struct{}),