mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 02:09:15 +02:00
envoy: improvements to logging (#742)
This commit is contained in:
parent
f40fb3d2ea
commit
84378440f0
1 changed files with 18 additions and 16 deletions
|
@ -68,8 +68,9 @@ func (srv *Server) Run(ctx context.Context) error {
|
||||||
srv.cmd = exec.CommandContext(ctx, envoyPath,
|
srv.cmd = exec.CommandContext(ctx, envoyPath,
|
||||||
"-c", configFileName,
|
"-c", configFileName,
|
||||||
"--log-level", log.Logger.GetLevel().String(),
|
"--log-level", log.Logger.GetLevel().String(),
|
||||||
"--log-format", "%l--%n--%v",
|
"--log-format", "[LOG_FORMAT]%l--%n--%v",
|
||||||
"--log-format-escaped",
|
"--log-format-escaped",
|
||||||
|
"--disable-hot-restart",
|
||||||
)
|
)
|
||||||
srv.cmd.Dir = srv.wd
|
srv.cmd.Dir = srv.wd
|
||||||
|
|
||||||
|
@ -132,35 +133,36 @@ static_resources:
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) handleLogs(stdout io.ReadCloser) {
|
func (srv *Server) handleLogs(stdout io.ReadCloser) {
|
||||||
fileNameAndNumberRE := regexp.MustCompile(`^(\[[^:]+:[0-9]+\])\s(.*)$`)
|
logFormatRE := regexp.MustCompile(`^[[]LOG_FORMAT[]](.*?)--(.*?)--(.*?)$`)
|
||||||
|
fileNameAndNumberRE := regexp.MustCompile(`^(\[[a-zA-Z0-9/-_.]+:[0-9]+])\s(.*)$`)
|
||||||
|
|
||||||
s := bufio.NewScanner(stdout)
|
s := bufio.NewScanner(stdout)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
ln := s.Text()
|
ln := s.Text()
|
||||||
|
|
||||||
// format: level--name--message
|
// format: [LOG_FORMAT]level--name--message
|
||||||
// message is c-escaped
|
// message is c-escaped
|
||||||
|
|
||||||
lvl := zerolog.TraceLevel
|
lvl := zerolog.DebugLevel
|
||||||
if pos := strings.Index(ln, "--"); pos >= 0 {
|
name := "envoy"
|
||||||
lvlstr := ln[:pos]
|
msg := ln
|
||||||
ln = ln[pos+2:]
|
parts := logFormatRE.FindStringSubmatch(ln)
|
||||||
if x, err := zerolog.ParseLevel(lvlstr); err == nil {
|
if len(parts) == 4 {
|
||||||
|
if x, err := zerolog.ParseLevel(parts[1]); err == nil {
|
||||||
lvl = x
|
lvl = x
|
||||||
}
|
}
|
||||||
|
name = parts[2]
|
||||||
|
msg = parts[3]
|
||||||
}
|
}
|
||||||
|
|
||||||
name := ""
|
msg = fileNameAndNumberRE.ReplaceAllString(msg, "\"$2\"")
|
||||||
if pos := strings.Index(ln, "--"); pos >= 0 {
|
|
||||||
name = ln[:pos]
|
|
||||||
ln = ln[pos+2:]
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := fileNameAndNumberRE.ReplaceAllString(ln, "\"$2\"")
|
|
||||||
if s, err := strconv.Unquote(msg); err == nil {
|
if s, err := strconv.Unquote(msg); err == nil {
|
||||||
msg = s
|
msg = s
|
||||||
}
|
}
|
||||||
|
|
||||||
log.WithLevel(lvl).Str("service", "envoy").Str("name", name).Msg(msg)
|
log.WithLevel(lvl).
|
||||||
|
Str("service", "envoy").
|
||||||
|
Str("name", name).
|
||||||
|
Msg(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue