atc: standarize syslog logging format
@@ -40,14 +40,14 @@ func (d *drainer) Run(ctx context.Context) error {
builds, err := d.buildFactory.GetDrainableBuilds()
if err != nil {
- logger.Error("Syslog drainer getting drainable builds error.", err)
+ logger.Error("failed-to-get-drainable-builds", err)
return err
}
if len(builds) > 0 {
syslog, err := Dial(d.transport, d.address, d.caCerts)
if err != nil {
- logger.Error("Syslog drainer connecting to server error.", err)
+ logger.Error("failed-to-connect", err)
return err
}
@@ -65,9 +65,15 @@ func (d *drainer) Run(ctx context.Context) error {
}
func (d *drainer) drainBuild(logger lager.Logger, build db.Build, syslog *Syslog) error {
+ logger = logger.Session("drain-build", lager.Data{
+ "team": build.TeamName(),
+ "pipeline": build.PipelineName(),
+ "job": build.JobName(),
+ "build": build.Name(),
+ })
+
events, err := build.Events(0)
if err != nil {
- logger.Error("Syslog drainer getting build events error.", err)
return err
}
@@ -80,26 +86,25 @@ func (d *drainer) drainBuild(logger lager.Logger, build db.Build, syslog *Syslog
if err == db.ErrEndOfBuildEventStream {
break
}
- logger.Error("Syslog drainer getting next event error.", err)
+ logger.Error("failed-to-get-next-event", err)
return err
}
- if ev.Event == "log" {
+ if ev.Event == event.EventTypeLog {
var log event.Log
err := json.Unmarshal(*ev.Data, &log)
if err != nil {
- logger.Error("Syslog drainer unmarshalling log error.", err)
+ logger.Error("failed-to-unmarshal", err)
return err
}
payload := log.Payload
tag := build.TeamName() + "/" + build.PipelineName() + "/" + build.JobName() + "/" + build.Name() + "/" + string(log.Origin.ID)
-
err = syslog.Write(d.hostname, tag, time.Unix(log.Time, 0), payload)
if err != nil {
- logger.Error("Syslog drainer sending to server error.", err)
+ logger.Error("failed-to-write-to-server", err, lager.Data{"tag": tag})
return err
}
}
@@ -107,7 +112,7 @@ func (d *drainer) drainBuild(logger lager.Logger, build db.Build, syslog *Syslog
err = build.SetDrained(true)
if err != nil {
- logger.Error("Syslog drainer setting drained on build error.", err)
+ logger.Error("failed-to-update-status", err)
return err
}
