mirror of https://github.com/curusarn/resh
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
806 B
27 lines
806 B
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/curusarn/resh/internal/datadir"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
func New(executable string, level zapcore.Level, development string) (*zap.Logger, error) {
|
|
dataDir, err := datadir.GetPath()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error while getting resh data dir: %w", err)
|
|
}
|
|
logPath := filepath.Join(dataDir, "log.json")
|
|
loggerConfig := zap.NewProductionConfig()
|
|
loggerConfig.OutputPaths = []string{logPath}
|
|
loggerConfig.Level.SetLevel(level)
|
|
loggerConfig.Development = development == "true" // DPanic panics in development
|
|
logger, err := loggerConfig.Build()
|
|
if err != nil {
|
|
return logger, fmt.Errorf("error while creating logger: %w", err)
|
|
}
|
|
return logger.With(zap.String("executable", executable)), err
|
|
}
|
|
|