Skip to content

Commit

Permalink
bug: replace the global logger with custom logger for client on Windows
Browse files Browse the repository at this point in the history
Updates #467
  • Loading branch information
panjf2000 committed May 19, 2023
1 parent b493107 commit dd46b08
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions client_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ import (
)

type Client struct {
opts *Options
el *eventloop
logFlush func() error
opts *Options
el *eventloop
}

func NewClient(eh EventHandler, opts ...Option) (cli *Client, err error) {
options := loadOptions(opts...)
cli = &Client{opts: options}
var logger logging.Logger
if options.LogPath != "" {
if logger, cli.logFlush, err = logging.CreateLoggerAsLocalFile(options.LogPath, options.LogLevel); err != nil {
return
}
} else {
logger = logging.GetDefaultLogger()
}

logger, logFlusher := logging.GetDefaultLogger(), logging.GetDefaultFlusher()
if options.Logger == nil {
if options.LogPath != "" {
logger, logFlusher, _ = logging.CreateLoggerAsLocalFile(options.LogPath, options.LogLevel)
}
options.Logger = logger
} else {
logger = options.Logger
logFlusher = nil
}
logging.SetDefaultLoggerAndFlusher(logger, logFlusher)

shutdownCtx, shutdown := context.WithCancel(context.Background())
eng := &engine{
Expand Down Expand Up @@ -78,6 +78,7 @@ func (cli *Client) Start() error {
return nil
})
}
logging.Debugf("default logging level is %s", logging.LogLevel())
return nil
}

Expand All @@ -88,9 +89,6 @@ func (cli *Client) Stop() (err error) {
}
_ = cli.el.eng.workerPool.Wait()
cli.el.eventHandler.OnShutdown(Engine{})
if cli.logFlush != nil {
err = cli.logFlush()
}
logging.Cleanup()
return
}
Expand Down

0 comments on commit dd46b08

Please sign in to comment.