Created
May 31, 2021 08:50
-
-
Save rogerBridge/f04b431d787a5d90b63eec36c7a2c412 to your computer and use it in GitHub Desktop.
logrus config
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
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", | |
}) |
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
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