Skip to content

add psr-3 compatibility #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/docker-fpm-wrapper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type Config struct {
LogLevel int `mapstructure:"log-level"`
LogLevel string `mapstructure:"log-level"`
LogEncoder string `mapstructure:"log-encoder"`

FpmPath string `mapstructure:"fpm"`
Expand All @@ -32,7 +32,7 @@ type Config struct {
}

func parseCommandLineFlags() {
pflag.Int8("log-level", -1, "Log level. -1 debug ")
pflag.String("log-level", "-1", "Log level. -1 debug ")
pflag.String("log-encoder", "auto", "Internal logging encoder")

pflag.StringP("fpm", "f", "", "path to php-fpm")
Expand Down
4 changes: 2 additions & 2 deletions cmd/docker-fpm-wrapper/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func createLoggerEncoder(eName string, encoderConfig zapcore.EncoderConfig) (zap
}
}

func createLogger(encName string, level int, output zapcore.WriteSyncer) (*zap.Logger, error) {
func createLogger(encName string, level zapcore.Level, output zapcore.WriteSyncer) (*zap.Logger, error) {
enc, err := createLoggerEncoder(encName, newZapEncoderConfig())
if err != nil {
return nil, err
}

atomicLevel := zap.NewAtomicLevelAt(zapcore.Level(level))
atomicLevel := zap.NewAtomicLevelAt(level)

return zap.New(zapcore.NewCore(enc, output, atomicLevel)), nil
}
17 changes: 16 additions & 1 deletion cmd/docker-fpm-wrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"
"os/signal"
"strconv"
"syscall"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -42,7 +43,21 @@ func main() {
}

syncStderr := zapcore.Lock(os.Stderr)
log, err := createLogger(cfg.LogEncoder, cfg.LogLevel, syncStderr)
// cfg.LogLevel can be either int or string
// example: it can be -1 or debug
// try to parse it by string
logLever, err := zapcore.ParseLevel(cfg.LogLevel)
if err != nil {
// so, the string is not correct, try to parse it as int
logLeverRaw, err := strconv.Atoi(cfg.LogLevel)
if err != nil {
fmt.Printf("Can't parse log level '%v': %v\n", cfg.LogLevel, err)
os.Exit(1)
}
logLever = zapcore.Level(logLeverRaw)
}

log, err := createLogger(cfg.LogEncoder, logLever, syncStderr)

if cfg.FpmPath == "" {
log.Error("php-fpm path not set")
Expand Down