Skip to content

Commit

Permalink
fix: use file.opt instead of opt when setting logger creating a file …
Browse files Browse the repository at this point in the history
…instance. (#97)

* fix: use file.opt instead of opt when setting logger.

If pe.New function is called with nil as opts parameter, panic occurs due to comparing opts.logger(which opt is nil), so use file.opts instead.

* fix: use file.opts.logger for NewBytes function
  • Loading branch information
Snshadow authored Jun 20, 2024
1 parent f9f7d40 commit 7d77b63
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ func New(name string, opts *Options) (*File, error) {
}

var logger log.Logger
if opts.Logger == nil {
if file.opts.Logger == nil {
logger = log.NewStdLogger(os.Stdout)
file.logger = log.NewHelper(log.NewFilter(logger,
log.FilterLevel(log.LevelError)))
} else {
file.logger = log.NewHelper(opts.Logger)
file.logger = log.NewHelper(file.opts.Logger)
}

file.data = data
Expand All @@ -176,7 +176,7 @@ func NewBytes(data []byte, opts *Options) (*File, error) {
}

var logger log.Logger
if opts.Logger == nil {
if file.opts.Logger == nil {
logger = log.NewStdLogger(os.Stdout)
file.logger = log.NewHelper(log.NewFilter(logger,
log.FilterLevel(log.LevelError)))
Expand Down

0 comments on commit 7d77b63

Please sign in to comment.