In my application I want to show only info log level at console and want to skip all debug log messages from console, but in log file I want both info and debug logs.
e.g.
var logrusLogger *logrus.Logger
var f *os.File
func main() {
f, err := os.OpenFile("mylog.log", os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
fmt.Println("Failed to create logfile mylog.log")
panic(err)
}
logrusLogger = logrus.New()
logrusLogger.SetFormatter(&logrus.TextFormatter{
ForceColors: false, //Enable this for coloured output
DisableColors: false,
TimestampFormat: "2006-01-02 15:04:05.000",
DisableTimestamp: false,
FullTimestamp: true,
})
logLevel, err := logrus.ParseLevel(os.Getenv("MY_LOG_LEVEL"))
if err != nil {
logLevel = logrus.DebugLevel
}
logrusLogger.SetLevel(logLevel)
logrusLogger.Out = io.MultiWriter(f, os.Stdout) //print logs in console as well inside tcxctl_<date>_.log file
logrusLogger.Info("=> This should print on console as well as inside mylog.log file <=")
logrusLogger.Debug("=>This should not print on console but should be inside mylog.log file <=")
}
I am not sure how I can achieve this using logrus, If anybody have any idea please share.
Hi ,
In my application I want to show only info log level at console and want to skip all debug log messages from console, but in log file I want both info and debug logs. e.g.
I am not sure how I can achieve this using logrus, If anybody have any idea please share.