package log
import (
+ "fmt"
+ "io/ioutil"
+ "os"
"path/filepath"
+ "strings"
"sync"
"time"
var defaultFormatter = &logrus.TextFormatter{DisableColors: true}
-func InitLogFile(config *config.Config) {
- hook := newBtmHook(config.LogDir())
+func InitLogFile(config *config.Config) error {
+ logPath := config.LogDir()
+ if err := clearLockFiles(logPath); err != nil {
+ return err
+ }
+
+ hook := newBtmHook(logPath)
logrus.AddHook(hook)
+ logrus.SetOutput(ioutil.Discard)//控制台不输出
+ fmt.Printf("all logs are output in the %s directory\n", logPath)
+ return nil
}
type BtmHook struct {
return err
}
+func clearLockFiles(logPath string) error {
+ files, err := ioutil.ReadDir(logPath)
+ if err != nil {
+ return err
+ }
+
+ for _, file := range files {
+ if ok := strings.HasSuffix(file.Name(), "_lock"); ok {
+ if err := os.Remove(filepath.Join(logPath, file.Name()));err!=nil{
+ return err
+ }
+ }
+ }
+ return nil
+}
+
func (hook *BtmHook) Fire(entry *logrus.Entry) error {
hook.lock.Lock()
defer hook.lock.Unlock()
cmn.Exit(cmn.Fmt("Failed to load federated information:[%s]", err.Error()))
}
- vaporLog.InitLogFile(config)
+ if err:=vaporLog.InitLogFile(config);err!=nil{
+ log.WithField("err",err).Fatalln("InitLogFile failed")
+ }
log.WithFields(log.Fields{
"module": logModule,
defaultRecvMessageCapacity = 22020096 // 21MB
defaultRecvRate = int64(104857600) // 100MB/s
defaultSendTimeout = 10 * time.Second
- logModule = "p2p/conn"
+ logModule = "p2pConn"
)
type receiveCbFunc func(chID byte, msgBytes []byte)