forked from prysmaticlabs/prysm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
logutil.go
32 lines (26 loc) · 859 Bytes
/
logutil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Package logutil creates a Multi writer instance that
// write all logs that are written to stdout.
package logutil
import (
"io"
"os"
"reflect"
"runtime"
"github.com/sirupsen/logrus"
)
// ConfigurePersistentLogging adds a log-to-file writer. File content is identical to stdout.
func ConfigurePersistentLogging(logFileName string) error {
logrus.WithField("logFileName", logFileName).Info("Logs will be made persistent")
f, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
return err
}
mw := io.MultiWriter(os.Stdout, f)
logrus.SetOutput(mw)
logrus.Info("File logging initialized")
return nil
}
// FunctionName returns the string representation of the function name for some interface.
func FunctionName(i interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}