How do I mask sensitive data using logrus in Go?

Go, Logrus, Mask sensitive data, logging, security
Learn how to effectively mask sensitive data using Logrus in Go to enhance the security of your logging mechanism.
package main import ( "github.com/sirupsen/logrus" "os" ) func main() { // Initialize logrus logger logger := logrus.New() // Set output to standard out logger.SetOutput(os.Stdout) // Set log level logger.SetLevel(logrus.InfoLevel) // Example sensitive data sensitiveInfo := "user@example.com" maskedInfo := maskSensitiveData(sensitiveInfo) // Log masked data logger.WithFields(logrus.Fields{ "sensitive": maskedInfo, }).Info("User logged in") // Log original data for debugging (Make sure to remove or protect this in production) logger.Debug("Original sensitive data: ", sensitiveInfo) } // maskSensitiveData masks the sensitive information func maskSensitiveData(info string) string { // Simple masking implementation return "****@" + info[strings.LastIndex(info, "@"):] }

Go Logrus Mask sensitive data logging security