prysm-pulse/shared/logutil/logutil.go
Raul Jordan 3197748240
Streaming Logs via Websocket Server (#7240)
* Log streaming proof of concept

* fix broken imports

* imports

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-09-16 09:03:52 -05:00

31 lines
797 B
Go

// Package logutil creates a Multi writer instance that
// write all logs that are written to stdout.
package logutil
import (
"io"
"os"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/sirupsen/logrus"
)
func addLogWriter(w io.Writer) {
mw := io.MultiWriter(logrus.StandardLogger().Out, w)
logrus.SetOutput(mw)
}
// 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, params.BeaconIoConfig().ReadWritePermissions)
if err != nil {
return err
}
addLogWriter(f)
logrus.Info("File logging initialized")
return nil
}