prysm-pulse/shared/logutil/logutil.go

31 lines
797 B
Go
Raw Normal View History

Persistent logs (#2660) * added file log feature * moved the logic to one central location (shared/logutil/logutil.go), removed new line chars from file logs * removed a resdundant temp file refrences that went into beachon-chain/BUILD.bazel by mistake * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * manually added loguitl dep to the go image target * Manaully added the logutil dep to the go image target * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * syntax and styling changes required by code reviewers * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * changed the return type of 'ConfigurePersistentLogging' from bool, error to error based on recommendation from code review * ran goimports in beacon-chain/main.go after tests have failed * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Changes requested by code reviewer * Added a mandatory comment (linter required) to the 'Fire' event * Changed the beacon-chain and validator to support only same format stdout and file logging due to complications in the outputs when using different formats. * Had to run gazelle --fix due to check failure
2019-05-22 13:22:11 +00:00
// Package logutil creates a Multi writer instance that
// write all logs that are written to stdout.
package logutil
import (
"io"
"os"
2020-06-25 16:12:59 +00:00
"github.com/prysmaticlabs/prysm/shared/params"
Persistent logs (#2660) * added file log feature * moved the logic to one central location (shared/logutil/logutil.go), removed new line chars from file logs * removed a resdundant temp file refrences that went into beachon-chain/BUILD.bazel by mistake * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * manually added loguitl dep to the go image target * Manaully added the logutil dep to the go image target * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * syntax and styling changes required by code reviewers * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * changed the return type of 'ConfigurePersistentLogging' from bool, error to error based on recommendation from code review * ran goimports in beacon-chain/main.go after tests have failed * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Changes requested by code reviewer * Added a mandatory comment (linter required) to the 'Fire' event * Changed the beacon-chain and validator to support only same format stdout and file logging due to complications in the outputs when using different formats. * Had to run gazelle --fix due to check failure
2019-05-22 13:22:11 +00:00
"github.com/sirupsen/logrus"
)
func addLogWriter(w io.Writer) {
mw := io.MultiWriter(logrus.StandardLogger().Out, w)
logrus.SetOutput(mw)
}
Persistent logs (#2660) * added file log feature * moved the logic to one central location (shared/logutil/logutil.go), removed new line chars from file logs * removed a resdundant temp file refrences that went into beachon-chain/BUILD.bazel by mistake * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * manually added loguitl dep to the go image target * Manaully added the logutil dep to the go image target * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * syntax and styling changes required by code reviewers * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * changed the return type of 'ConfigurePersistentLogging' from bool, error to error based on recommendation from code review * ran goimports in beacon-chain/main.go after tests have failed * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Changes requested by code reviewer * Added a mandatory comment (linter required) to the 'Fire' event * Changed the beacon-chain and validator to support only same format stdout and file logging due to complications in the outputs when using different formats. * Had to run gazelle --fix due to check failure
2019-05-22 13:22:11 +00:00
// 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")
2020-06-25 16:12:59 +00:00
f, err := os.OpenFile(logFileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, params.BeaconIoConfig().ReadWritePermissions)
Persistent logs (#2660) * added file log feature * moved the logic to one central location (shared/logutil/logutil.go), removed new line chars from file logs * removed a resdundant temp file refrences that went into beachon-chain/BUILD.bazel by mistake * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * manually added loguitl dep to the go image target * Manaully added the logutil dep to the go image target * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * syntax and styling changes required by code reviewers * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * changed the return type of 'ConfigurePersistentLogging' from bool, error to error based on recommendation from code review * ran goimports in beacon-chain/main.go after tests have failed * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Changes requested by code reviewer * Added a mandatory comment (linter required) to the 'Fire' event * Changed the beacon-chain and validator to support only same format stdout and file logging due to complications in the outputs when using different formats. * Had to run gazelle --fix due to check failure
2019-05-22 13:22:11 +00:00
if err != nil {
return err
}
addLogWriter(f)
Persistent logs (#2660) * added file log feature * moved the logic to one central location (shared/logutil/logutil.go), removed new line chars from file logs * removed a resdundant temp file refrences that went into beachon-chain/BUILD.bazel by mistake * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * Update shared/cmd/flags.go Co-Authored-By: shayzluf <thezluf@gmail.com> * manually added loguitl dep to the go image target * Manaully added the logutil dep to the go image target * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * syntax and styling changes required by code reviewers * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * changed the return type of 'ConfigurePersistentLogging' from bool, error to error based on recommendation from code review * ran goimports in beacon-chain/main.go after tests have failed * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update beacon-chain/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update shared/logutil/logutil.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/main.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * Changes requested by code reviewer * Added a mandatory comment (linter required) to the 'Fire' event * Changed the beacon-chain and validator to support only same format stdout and file logging due to complications in the outputs when using different formats. * Had to run gazelle --fix due to check failure
2019-05-22 13:22:11 +00:00
logrus.Info("File logging initialized")
return nil
}