Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
config: change redact log parameter name (#547)
Browse files Browse the repository at this point in the history
* change redact log parameter name

* address comment

* update lightning.toml
  • Loading branch information
lichunzhu authored Jan 13, 2021
1 parent 161f005 commit 0c9788e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lightning/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ type Security struct {
CAPath string `toml:"ca-path" json:"ca-path"`
CertPath string `toml:"cert-path" json:"cert-path"`
KeyPath string `toml:"key-path" json:"key-path"`
// RedactInfoLog indicates that whether enabling redact log
RedactInfoLog bool `toml:"redact-info-log" json:"redact-info-log"`
}

// RegistersMySQL registers (or deregisters) the TLS config with name "cluster"
Expand Down
8 changes: 4 additions & 4 deletions lightning/config/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func LoadGlobalConfig(args []string, extraFlags func(*flag.FlagSet)) (*GlobalCon

logLevel := flagext.ChoiceVar(fs, "L", "", `log level: info, debug, warn, error, fatal (default info)`, "", "info", "debug", "warn", "warning", "error", "fatal")
logFilePath := fs.String("log-file", "", "log file path")
redactLog := fs.Bool("redact-log", false, "whether to redact sensitive info in log")
tidbHost := fs.String("tidb-host", "", "TiDB server host")
tidbPort := fs.Int("tidb-port", 0, "TiDB server port (default 4000)")
tidbUser := fs.String("tidb-user", "", "TiDB user name to connect")
Expand All @@ -163,6 +162,7 @@ func LoadGlobalConfig(args []string, extraFlags func(*flag.FlagSet)) (*GlobalCon
tlsCAPath := fs.String("ca", "", "CA certificate path for TLS connection")
tlsCertPath := fs.String("cert", "", "certificate path for TLS connection")
tlsKeyPath := fs.String("key", "", "private key path for TLS connection")
redactInfoLog := fs.Bool("redact-info-log", false, "whether to redact sensitive info in log")

statusAddr := fs.String("status-addr", "", "the Lightning server address")
serverMode := fs.Bool("server-mode", false, "start Lightning in server mode, wait for multiple tasks instead of starting immediately")
Expand Down Expand Up @@ -199,9 +199,6 @@ func LoadGlobalConfig(args []string, extraFlags func(*flag.FlagSet)) (*GlobalCon
if *logFilePath != "" {
cfg.App.Config.File = *logFilePath
}
if *redactLog {
cfg.App.Config.RedactLog = *redactLog
}
// "-" is a special config for log to stdout
if cfg.App.Config.File == "-" {
cfg.App.Config.File = ""
Expand Down Expand Up @@ -271,6 +268,9 @@ func LoadGlobalConfig(args []string, extraFlags func(*flag.FlagSet)) (*GlobalCon
if *tlsKeyPath != "" {
cfg.Security.KeyPath = *tlsKeyPath
}
if *redactInfoLog {
cfg.Security.RedactInfoLog = *redactInfoLog
}
if len(filter) > 0 {
cfg.Mydumper.Filter = filter
}
Expand Down
2 changes: 2 additions & 0 deletions lightning/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func New(globalCfg *config.GlobalConfig) *Lightning {
log.L().Fatal("failed to load TLS certificates", zap.Error(err))
}

log.InitRedact(globalCfg.Security.RedactInfoLog)

ctx, shutdown := context.WithCancel(context.Background())
return &Lightning{
globalCfg: globalCfg,
Expand Down
4 changes: 0 additions & 4 deletions lightning/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ type Config struct {
FileMaxDays int `toml:"max-days" json:"max-days"`
// Maximum number of old log files to retain.
FileMaxBackups int `toml:"max-backups" json:"max-backups"`
// Redact sensitive logs during the whole process
RedactLog bool `toml:"redact-log" json:"redact-log"`
}

func (cfg *Config) Adjust() {
Expand Down Expand Up @@ -100,8 +98,6 @@ func InitLogger(cfg *Config, tidbLoglevel string) error {
appLogger = Logger{logger.WithOptions(zap.AddStacktrace(zap.DPanicLevel))}
appLevel = props.Level

InitRedact(cfg.RedactLog)

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions tidb-lightning.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ file = "tidb-lightning.log"
max-size = 128 # MB
max-days = 28
max-backups = 14
# If set to true, lightning will redact sensitive infomation in log.
redact-log = false

[security]
# specifies certificates and keys for TLS connections within the cluster.
Expand All @@ -52,6 +50,8 @@ redact-log = false
# cert-path = "/path/to/lightning.pem"
# private key of this service.
# key-path = "/path/to/lightning.key"
# If set to true, lightning will redact sensitive infomation in log.
# redact-info-log = false

[checkpoint]
# Whether to enable checkpoints.
Expand Down

0 comments on commit 0c9788e

Please sign in to comment.