Skip to content

Instantly share code, notes, and snippets.

@rogerBridge
Created May 31, 2021 08:50
Show Gist options
  • Save rogerBridge/f04b431d787a5d90b63eec36c7a2c412 to your computer and use it in GitHub Desktop.
Save rogerBridge/f04b431d787a5d90b63eec36c7a2c412 to your computer and use it in GitHub Desktop.
logrus config
package logconf
import (
"os"
"github.com/sirupsen/logrus"
)
func init() {
// Log as JSON instead of the default ASCII formatter.
logrus.SetFormatter(&logrus.JSONFormatter{TimestampFormat: "2006-01-02 15:04:05.999"})
// Output to stdout instead of the default stderr
// Can be any io.Writer, see below for File example
logrus.SetOutput(os.Stdout)
// Only log the warning severity or above.
logrus.SetLevel(logrus.WarnLevel)
}
var BaseLogger = logrus.WithFields(logrus.Fields{
"app": "inputYourAppName",
"author": "inputYourName",
})
package main
func main() {
logger := logconf.BaseLogger.WithFields(logrus.Fields{"component": "main"})
logger.Warn()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment