Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
/ redact Public archive

Redact is as a fast, resource-efficient library for redacting Logrus logs using struct tags.

License

Notifications You must be signed in to change notification settings

squeakycheese75/redact

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redact

Redact is as a fast, resource-efficient library for redacting Logrus logs with struct tags.

Usage

To use Redact, with logrus:

package main

import (
	"encoding/json"

	log "github.com/sirupsen/logrus"
	"github.com/squeakycheese75/redact"
)

type Guest struct {
	Name    string `json:"name"`
	Species string `json:"species" redact:"[REDACTED]"`
}

type Party struct {
	GuestList []*Guest `json:"guest_list"`
	Date      string   `json:"date"`
	Venue     string   `json:"venue" redact:"[REDACTED]"`
}

func main() {
	log.SetFormatter(&log.JSONFormatter{PrettyPrint: true})

	barry := &Guest{Name: "barry", Species: "seal"}
	patricia := &Guest{Name: "patricia", Species: "penguin"}
	morris := &Guest{Name: "morris", Species: "mackeral"}

	myParty := &Party{
		GuestList: []*Guest{barry, patricia, morris},
		Date:      "Tuesday",
		Venue:     "Barrys Place",
	}

	log.WithFields(log.Fields{
		"animal": "walrus",
		"party":  myParty,
	}).Info("A walrus is having a party")


    log.WithFields(log.Fields{
		"animal": "walrus",
		"party":  redact.Redact(myParty),
	}).Info("A walrus is having a [REDACTED] party")
}

results...

{
  "animal": "walrus",
  "level": "info",
  "msg": "A walrus is having a party",
  "party": {
    "guest_list": [
      {
        "name": "barry",
        "species": "seal"
      },
      {
        "name": "patricia",
        "species": "penguin"
      },
      {
        "name": "morris",
        "species": "mackeral"
      }
    ],
    "date": "Tuesday",
    "venue": "[REDACTED]"
  },
  "time": "2023-04-22T12:49:46+02:00"
}

Alternates

Take a look at Redactrus.

About

Redact is as a fast, resource-efficient library for redacting Logrus logs using struct tags.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages