From 76b0286b68b5c5554278ddd3a7b24ffeff3425af Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 29 Sep 2016 17:45:13 -0400 Subject: [PATCH] update agent logs --- agent/updater.go | 5 +++-- build/pipeline.go | 4 ---- drone/agent/agent.go | 27 ++++++++++++++++----------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/agent/updater.go b/agent/updater.go index e2e1f43ad..90fc999f7 100644 --- a/agent/updater.go +++ b/agent/updater.go @@ -6,6 +6,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/drone/drone/build" "github.com/drone/drone/model" + "github.com/drone/mq/logger" "github.com/drone/mq/stomp" ) @@ -27,7 +28,7 @@ func NewClientUpdater(client *stomp.Client) UpdateFunc { return func(w *model.Work) { err := client.SendJSON("/queue/updates", w) if err != nil { - logrus.Errorf("Error updating %s/%s#%d.%d. %s", + logger.Warningf("Error updating %s/%s#%d.%d. %s", w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number, err) } if w.Job.Status != model.StatusRunning { @@ -38,7 +39,7 @@ func NewClientUpdater(client *stomp.Client) UpdateFunc { } if err := client.Send(dest, []byte("eof"), opts...); err != nil { - logrus.Errorf("Error sending eof %s/%s#%d.%d. %s", + logger.Warningf("Error sending eof %s/%s#%d.%d. %s", w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number, err) } } diff --git a/build/pipeline.go b/build/pipeline.go index ddeca757b..7b83d1f46 100644 --- a/build/pipeline.go +++ b/build/pipeline.go @@ -175,7 +175,6 @@ func (p *Pipeline) exec(c *yaml.Container) error { } p.containers = append(p.containers, name) - logrus.Debugf("wait.add(1) for %s logs", name) p.wait.Add(1) go func() { defer func() { @@ -183,7 +182,6 @@ func (p *Pipeline) exec(c *yaml.Container) error { logrus.Errorln("recover writing build output", r) } - logrus.Debugf("wait.done() for %s logs", name) p.wait.Done() }() @@ -217,7 +215,6 @@ func (p *Pipeline) exec(c *yaml.Container) error { return err } - logrus.Debugf("wait.add(1) for %s exit code", name) p.wait.Add(1) go func() { defer func() { @@ -225,7 +222,6 @@ func (p *Pipeline) exec(c *yaml.Container) error { logrus.Errorln("recover writing exit code to output", r) } p.wait.Done() - logrus.Debugf("wait.done() for %s exit code", name) }() p.pipe <- &Line{ diff --git a/drone/agent/agent.go b/drone/agent/agent.go index b3037a701..c9a51eaaa 100644 --- a/drone/agent/agent.go +++ b/drone/agent/agent.go @@ -9,7 +9,9 @@ import ( "time" "github.com/drone/drone/model" + "github.com/drone/mq/logger" "github.com/drone/mq/stomp" + "github.com/tidwall/redlog" "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" @@ -136,9 +138,15 @@ var AgentCmd = cli.Command{ func start(c *cli.Context) { + log := redlog.New(os.Stderr) + log.SetLevel(0) + logger.SetLogger(log) + // debug level if requested by user if c.Bool("debug") { logrus.SetLevel(logrus.DebugLevel) + + log.SetLevel(1) } else { logrus.SetLevel(logrus.WarnLevel) } @@ -152,10 +160,7 @@ func start(c *cli.Context) { accessToken = c.String("drone-token") } - logrus.Infof("Connecting to %s with token %s", - c.String("drone-server"), - accessToken, - ) + logger.Noticef("connecting to server%s", c.String("drone-server")) server := strings.TrimRight(c.String("drone-server"), "/") @@ -203,7 +208,7 @@ func start(c *cli.Context) { // dial the drone server to establish a TCP connection. client, err = stomp.Dial(server) if err != nil { - logrus.Errorf("Failed to establish server connection, %s, retry in %v", err, backoff) + logger.Warningf("connection failed, retry in %v. %s", backoff, err) <-time.After(backoff) continue } @@ -213,7 +218,7 @@ func start(c *cli.Context) { // initialize the stomp session and authenticate. if err = client.Connect(opts...); err != nil { - logrus.Errorf("Failed to establish server session, %s, retry in %v", err, backoff) + logger.Warningf("session failed, retry in %v", backoff, err) <-time.After(backoff) continue } @@ -233,10 +238,10 @@ func start(c *cli.Context) { go handler(m) // HACK until we a channel based Subscribe implementation }), opts...) - logrus.Infof("Server connection establish, ready to process builds.") + logger.Noticef("connection establish, ready to process builds.") <-client.Done() - logrus.Warnf("Server connection interrupted, attempting to reconnect.") + logger.Warningf("connection interrupted, attempting to reconnect.") } } @@ -251,10 +256,10 @@ func handleSignals() { go func() { <-c - logrus.Debugln("SIGTERM received.") - logrus.Debugln("wait for running builds to finish.") + logger.Warningf("SIGTERM received.") + logger.Warningf("wait for running builds to finish.") running.Wait() - logrus.Debugln("done.") + logger.Warningf("done.") os.Exit(0) }() }