github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/redact/redact.go (about)

     1  // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
     2  
     3  package redact
     4  
     5  import (
     6  	"encoding/hex"
     7  	"strings"
     8  
     9  	"github.com/pingcap/errors"
    10  )
    11  
    12  // InitRedact inits the enableRedactLog
    13  func InitRedact(redactLog bool) {
    14  	errors.RedactLogEnabled.Store(redactLog)
    15  }
    16  
    17  // NeedRedact returns whether to redact log
    18  func NeedRedact() bool {
    19  	return errors.RedactLogEnabled.Load()
    20  }
    21  
    22  // String receives string argument and return omitted information if redact log enabled
    23  func String(arg string) string {
    24  	if NeedRedact() {
    25  		return "?"
    26  	}
    27  	return arg
    28  }
    29  
    30  // Key receives a key return omitted information if redact log enabled
    31  func Key(key []byte) string {
    32  	if NeedRedact() {
    33  		return "?"
    34  	}
    35  	return strings.ToUpper(hex.EncodeToString(key))
    36  }