mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
types/logger: add WithPrefix, use it in two places
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
758744a4e3
commit
3988ddc85d
@ -169,11 +169,8 @@ func Run(rctx context.Context, logf logger.Logf, logid string, opts Options, e w
|
||||
oldS = s
|
||||
|
||||
go func(ctx context.Context, bs *ipn.BackendServer, s net.Conn, i int) {
|
||||
// TODO: move this prefixing-Logf code into a new helper in types/logger?
|
||||
si := fmt.Sprintf("%d: ", i)
|
||||
pump(func(fmt string, args ...interface{}) {
|
||||
logf(si+fmt, args...)
|
||||
}, ctx, bs, s)
|
||||
logf := logger.WithPrefix(logf, fmt.Sprintf("%d: ", i))
|
||||
pump(logf, ctx, bs, s)
|
||||
if !opts.SurviveDisconnects || bs.GotQuit {
|
||||
bs.Reset()
|
||||
s.Close()
|
||||
|
@ -174,9 +174,7 @@ func (b *LocalBackend) Start(opts Options) error {
|
||||
persist = &controlclient.Persist{}
|
||||
}
|
||||
cli, err := controlclient.New(controlclient.Options{
|
||||
Logf: func(fmt string, args ...interface{}) {
|
||||
b.logf("control: "+fmt, args...)
|
||||
},
|
||||
Logf: logger.WithPrefix(b.logf, "control: "),
|
||||
Persist: *persist,
|
||||
ServerURL: b.serverURL,
|
||||
Hostinfo: hi,
|
||||
|
@ -7,4 +7,12 @@
|
||||
// types around.
|
||||
package logger
|
||||
|
||||
type Logf func(fmt string, args ...interface{})
|
||||
// Logf is the basic Tailscale logger type: a printf-like func.
|
||||
type Logf func(format string, args ...interface{})
|
||||
|
||||
// WithPrefix wraps f, prefixing each format with the provided prefix.
|
||||
func WithPrefix(f Logf, prefix string) Logf {
|
||||
return func(format string, args ...interface{}) {
|
||||
f(prefix+format, args...)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user