Skip to content

Commit

Permalink
fix(log): don't print querylog target password when using a database
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Apr 2, 2024
1 parent 28f979f commit 76353dd
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion config/query_log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"net/url"

"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -32,7 +34,7 @@ func (c *QueryLog) LogConfig(logger *logrus.Entry) {
logger.Infof("type: %s", c.Type)

if c.Target != "" {
logger.Infof("target: %s", c.Target)
logger.Infof("target: %s", c.censoredTarget())
}

logger.Infof("logRetentionDays: %d", c.LogRetentionDays)
Expand All @@ -41,3 +43,15 @@ func (c *QueryLog) LogConfig(logger *logrus.Entry) {
logger.Infof("flushInterval: %s", c.FlushInterval)
logger.Infof("fields: %s", c.Fields)
}

func (c *QueryLog) censoredTarget() string {
target, err := url.Parse(c.Target)
if err != nil || target.User == nil {
return c.Target
}

// Drop the password
target.User = url.User(target.User.Username())

return target.String()
}

0 comments on commit 76353dd

Please sign in to comment.