This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func RegisterLogrusLog(lc logconfig.LogConfig) (glogger.Logger, | |
| error) { | |
| //standard configuration | |
| log := logrus.New() | |
| log.SetFormatter(&logrus.TextFormatter{}) | |
| log.SetReportCaller(true) | |
| //log.SetOutput(os.Stdout) | |
| //customize it from configuration file | |
| err := customizeLogrusLogFromConfig(log, lc) | |
| if err != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const ( | |
| LOGRUS string = "logrus" | |
| ZAP string = "zap" | |
| GLOG string = "glog" | |
| ) | |
| // logger map to map logger code to logger builder | |
| var logfactoryBuilderMap = map[string]logFbInterface{ | |
| ZAP: &zap.ZapFactory{}, | |
| LOGRUS: &logrus.LogrusFactory{}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const ( | |
| LOGRUS string = "logrus" | |
| ZAP string = "zap" | |
| ) | |
| // logger mapp to map logger code to logger builder | |
| var logfactoryBuilderMap = map[string]logFbInterface{ | |
| ZAP: &zap.ZapFactory{}, | |
| LOGRUS: &logrus.LogrusFactory{}, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func initLogger (lc *logConfig.Logging) error{ | |
| log, err := logFactory.Build(lc) | |
| if err != nil { | |
| return errors.Wrap(err, "loadLogger") | |
| } | |
| logger.SetLogger(log) | |
| return nil | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func BuildConfig(filename ...string) (*AppConfig, error) { | |
| if len(filename) == 1 { | |
| return buildConfigFromFile(filename[0]) | |
| } else { | |
| return BuildConfigWithoutFile() | |
| } | |
| } | |
| func buildConfigFromFile(filename string) (*AppConfig, error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func InitApp(filename...string) (container.Container, error) { | |
| config, err := config.BuildConfig(filename...) | |
| if err != nil { | |
| return nil, errors.Wrap(err, "loadConfig") | |
| } | |
| err = initLogger(&config.LogConfig) | |
| if err != nil { | |
| return nil, err | |
| } | |
| return initContainer(config) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Logging struct { | |
| // log library name | |
| Code string `yaml:"code"` | |
| // log level | |
| Level string `yaml:"level"` | |
| // show caller in log message | |
| EnableCaller bool `yaml:"enableCaller"` | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func Build(lc *config.Logging) (glogger.Logger, error) { | |
| loggerType := lc.Code | |
| l, err := GetLogFactoryBuilder(loggerType).Build(lc) | |
| if err != nil { | |
| return l, errors.Wrap(err, "") | |
| } | |
| return l, nil | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func initLogger (lc *logConfig.Logging) error{ | |
| log, err := logFactory.Build(lc) | |
| if err != nil { | |
| return errors.Wrap(err, "loadLogger") | |
| } | |
| logger.SetLogger(log) | |
| return nil | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Logger interface { | |
| Errorf(format string, args ...interface{}) | |
| Fatalf(format string, args ...interface{}) | |
| Fatal(args ...interface{}) | |
| Infof(format string, args ...interface{}) | |
| Info(args ...interface{}) | |
| Warnf(format string, args ...interface{}) | |
| Debugf(format string, args ...interface{}) | |
| Debug(args ...interface{}) | |
| } |
NewerOlder