Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Migrate server.go logger to the app one instead of logrus (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislas-m authored and markbates committed Jun 22, 2018
1 parent c5f35a9 commit 88d7221
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import (
"github.com/markbates/refresh/refresh/web"
"github.com/markbates/sigtx"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

// Serve the application at the specified address/port and listen for OS
// interrupt and kill signals and will attempt to stop the application
// gracefully. This will also start the Worker process, unless WorkerOff is enabled.
func (a *App) Serve(srvs ...servers.Server) error {
logrus.Infof("Starting application at %s", a.Options.Host)
a.Logger.Infof("Starting application at %s", a.Options.Host)

if len(srvs) == 0 {
if strings.HasPrefix(a.Options.Addr, "unix:") {
Expand All @@ -38,23 +37,23 @@ func (a *App) Serve(srvs ...servers.Server) error {
go func() {
// gracefully shut down the application when the context is cancelled
<-ctx.Done()
logrus.Info("Shutting down application")
a.Logger.Info("Shutting down application")

if err := a.Stop(ctx.Err()); err != nil {
logrus.Error(err)
a.Logger.Error(err)
}

if !a.WorkerOff {
// stop the workers
logrus.Info("Shutting down worker")
a.Logger.Info("Shutting down worker")
if err := a.Worker.Stop(); err != nil {
logrus.Error(err)
a.Logger.Error(err)
}
}

for _, s := range srvs {
if err := s.Shutdown(ctx); err != nil {
logrus.Error(err)
a.Logger.Error(err)
}
}

Expand Down Expand Up @@ -86,7 +85,7 @@ func (a *App) Serve(srvs ...servers.Server) error {
func (a *App) Stop(err error) error {
a.cancel()
if err != nil && errors.Cause(err) != context.Canceled {
logrus.Error(err)
a.Logger.Error(err)
return err
}
return nil
Expand Down

0 comments on commit 88d7221

Please sign in to comment.