Rich Enhanced Shell History - Contextual shell history for zsh and bash
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.
 
 
 
resh/internal/logger/logger.go

27 lines
807 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.MakePath()
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
}