github.com/amazechain/amc@v0.1.3/cmd/amc/logger.go (about) 1 // Copyright 2022 The AmazeChain Authors 2 // This file is part of the AmazeChain library. 3 // 4 // The AmazeChain library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The AmazeChain library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 // 20 //var ( 21 // once sync.Once 22 //) 23 // 24 //func Init(nodeConfig *conf.NodeConfig, config *conf.LoggerConfig) (*zap.Logger, error) { 25 // 26 // var level zapcore.Level 27 // if err := level.Set(config.Level); err != nil { 28 // return nil, err 29 // } 30 // 31 // infoLevel := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { 32 // return lvl >= level && lvl < zapcore.ErrorLevel 33 // }) 34 // 35 // errorLevel := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { 36 // return lvl >= zapcore.ErrorLevel 37 // }) 38 // 39 // var Logger *zap.Logger 40 // 41 // once.Do(func() { 42 // encode := getEncoder() 43 // core := zapcore.NewTee( 44 // zapcore.NewCore(encode, getLogWriter(nodeConfig, config), infoLevel), 45 // zapcore.NewCore(encode, zapcore.AddSync(os.Stdout), level), 46 // zapcore.NewCore(encode, getErrorWriter(nodeConfig, config), errorLevel), 47 // ) 48 // 49 // Logger = zap.New(core, zap.AddCaller()) 50 // }) 51 // 52 // return Logger, nil 53 //} 54 // 55 //func getEncoder() zapcore.Encoder { 56 // encoderConfig := zap.NewProductionEncoderConfig() 57 // encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder 58 // encoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder 59 // encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder 60 // encoderConfig.EncodeName = zapcore.FullNameEncoder 61 // return zapcore.NewConsoleEncoder(encoderConfig) 62 //} 63 // 64 //func getLumberjack(path string, maxSize, maxBackups, maxAge int, compress bool) *lumberjackV2.Logger { 65 // return &lumberjackV2.Logger{ 66 // Filename: path, 67 // MaxSize: maxSize, 68 // MaxBackups: maxBackups, 69 // MaxAge: maxAge, 70 // Compress: compress, 71 // } 72 //} 73 // 74 //func getLogWriter(nodeConfig *conf.NodeConfig, config *conf.LoggerConfig) zapcore.WriteSyncer { 75 // return zapcore.AddSync(getLumberjack(fmt.Sprintf("%s/log/%s", nodeConfig.DataDir, config.LogFile), config.MaxSize, config.MaxBackups, config.MaxAge, config.Compress)) 76 //} 77 // 78 //func getErrorWriter(nodeConfig *conf.NodeConfig, config *conf.LoggerConfig) zapcore.WriteSyncer { 79 // var name string 80 // i := strings.LastIndex(config.LogFile, ".") 81 // if i <= 0 { 82 // name = fmt.Sprintf("%s_error.log", config.LogFile) 83 // } else { 84 // name = fmt.Sprintf("%s_error.log", config.LogFile[:i]) 85 // } 86 // return zapcore.AddSync(getLumberjack(fmt.Sprintf("%s/log/%s", nodeConfig.DataDir, name), config.MaxSize, config.MaxBackups, config.MaxAge, config.Compress)) 87 //}