Skip to content

Commit e7f9d93

Browse files
author
anahan
committed
enable php-fpm errlog parsing
1 parent 38d4bde commit e7f9d93

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

cmd/docker-fpm-wrapper/errlog.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"context"
5+
6+
"go.uber.org/zap"
7+
8+
"github.com/code-tool/docker-fpm-wrapper/internal/zapx"
9+
"github.com/code-tool/docker-fpm-wrapper/pkg/phpfpm"
10+
)
11+
12+
func startSlowlogProxy(ctx context.Context, log *zap.Logger, fPath string) error {
13+
if fPath == "" {
14+
return nil
15+
}
16+
17+
f, err := createFIFOByPathCtx(ctx, fPath)
18+
if err != nil {
19+
return err
20+
}
21+
22+
entryCh := make(chan phpfpm.ErrLogEntry)
23+
go func() {
24+
for {
25+
select {
26+
case entry := <-entryCh:
27+
// todo Map Level
28+
if ce := log.Check(zapx.MapFpmLogLevel(entry.Level), entry.Message); ce != nil {
29+
ce.Time = entry.CreatedAt
30+
ce.Write()
31+
}
32+
case <-ctx.Done():
33+
return
34+
}
35+
}
36+
}()
37+
38+
logParser := phpfpm.NewErrLogParser()
39+
go func() {
40+
_ = logParser.Parse(ctx, f, entryCh)
41+
}()
42+
43+
return nil
44+
}

cmd/docker-fpm-wrapper/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func main() {
7272
os.Exit(1)
7373
}
7474

75+
if err := startSlowlogProxy(ctx, log.Named("php-fpm"), fpmConfig.ErrorLog); err != nil {
76+
log.Error("can't start err_log proxy", zap.Error(err))
77+
}
78+
7579
if !cfg.FpmSlowlogProxyDisabled {
7680
if err = startSlowlogProxies(ctx, fpmConfig, log); err != nil {
7781
log.Fatal("Can't start slowlog proxies", zap.Error(err))

internal/zapx/level.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package zapx
2+
3+
import (
4+
"go.uber.org/zap"
5+
"go.uber.org/zap/zapcore"
6+
7+
"github.com/code-tool/docker-fpm-wrapper/pkg/phpfpm"
8+
)
9+
10+
func MapFpmLogLevel(ll phpfpm.LogLevel) zapcore.Level {
11+
switch ll {
12+
case phpfpm.LogLevelAlert:
13+
return zap.FatalLevel
14+
case phpfpm.LogLevelError:
15+
return zap.ErrorLevel
16+
case phpfpm.LogLevelWarning:
17+
return zap.WarnLevel
18+
case phpfpm.LogLevelNotice:
19+
return zap.InfoLevel
20+
case phpfpm.LogLevelDebug:
21+
return zap.DebugLevel
22+
default:
23+
return zap.DebugLevel
24+
}
25+
}

0 commit comments

Comments
 (0)