Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/vendor/github.com/anacrolix/torrent/logonce/logonce.go
akuma06 a41f938cec Add Godep support (#758)
As we have seen, dependencies version can prevent the build. We should
user lock versions on dependencies that we know work:
* Packages are vendored
* Add Godep support
* Added addtional install step in readme
* Fix travis build error
2017-05-26 13:07:22 +02:00

47 lignes
1,1 Kio
Go

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