From 56ba3fb765bbdc0d32b8e3a75e8fcdd23507d447 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Mon, 19 Jan 2015 14:54:53 +1100 Subject: [PATCH] log: add SetOutput method on Logger Fixes #9629 Change-Id: I66091003b97742ca6d857fe51d609833ab727216 Reviewed-on: https://go-review.googlesource.com/3023 Reviewed-by: Rob Pike --- src/log/log.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/log/log.go b/src/log/log.go index 0ef05d8f94b..17646a12fa8 100644 --- a/src/log/log.go +++ b/src/log/log.go @@ -60,6 +60,13 @@ func New(out io.Writer, prefix string, flag int) *Logger { return &Logger{out: out, prefix: prefix, flag: flag} } +// SetOutput sets the output destination for the logger. +func (l *Logger) SetOutput(w io.Writer) { + l.mu.Lock() + defer l.mu.Unlock() + l.out = w +} + var std = New(os.Stderr, "", LstdFlags) // Cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding.