Created
July 28, 2020 13:39
-
-
Save jfeng45/fe6bf2ffedfe0d59c00c76c201eb397e to your computer and use it in GitHub Desktop.
This file contains 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 { | |
return nil, errors.Wrap(err, "") | |
} | |
//This is for loggerWrapper implementation | |
//logger.Logger(&loggerWrapper{log}) | |
//SetLogger(log) | |
return log, nil | |
} | |
// customizeLogrusLogFromConfig customize log based on parameters from configuration file | |
func customizeLogrusLogFromConfig(log *logrus.Logger, lc logconfig.LogConfig) error { | |
log.SetReportCaller(lc.EnableCaller) | |
//log.SetOutput(os.Stdout) | |
l := &log.Level | |
err := l.UnmarshalText([]byte(lc.Level)) | |
if err != nil { | |
return errors.Wrap(err, "") | |
} | |
log.SetLevel(*l) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment