Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Make logger a named field of the container struct
Browse files Browse the repository at this point in the history
Go has trouble marshalling structs with anonymous fields.

Change-Id: I9e809307795f54d6f004e04b08bd648bfeb1a60a
  • Loading branch information
pietern committed Jan 15, 2013
1 parent 44ee193 commit 2be4308
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions go/src/warden/server/container.go
Expand Up @@ -37,6 +37,7 @@ type LinuxContainer struct {
c *config.Config
r chan chan *Request
s *Server
l steno.Logger

State State
Id string
Expand All @@ -48,8 +49,6 @@ type LinuxContainer struct {

IdleTimeout time.Duration

steno.Logger

// The map needs to use a string key because that cleanly serializes to JSON
JobId int
Jobs map[string]*Job
Expand Down Expand Up @@ -86,7 +85,7 @@ func NewContainer(s *Server, cfg *config.Config) *LinuxContainer {

// Setup container-specific logger
l := steno.NewLogger("container")
c.Logger = steno.NewTaggedLogger(l, map[string]string{"id": c.Id})
c.l = steno.NewTaggedLogger(l, map[string]string{"id": c.Id})

return c
}
Expand Down Expand Up @@ -157,7 +156,7 @@ func (c *LinuxContainer) snapshotPath() string {
func (c *LinuxContainer) markDirty() error {
err := os.Remove(c.snapshotPath())
if err != nil {
c.Warnf("Unable to remove snapshot: %s", err)
c.l.Warnf("Unable to remove snapshot: %s", err)
return err
}

Expand All @@ -171,7 +170,7 @@ func (c *LinuxContainer) markClean() error {
x := path.Join(c.ContainerPath(), "tmp")
y, err := ioutil.TempFile(x, "snapshot")
if err != nil {
c.Warnf("Unable to create snapshot file: %s", err)
c.l.Warnf("Unable to create snapshot file: %s", err)
return err
}

Expand All @@ -180,11 +179,11 @@ func (c *LinuxContainer) markClean() error {

b, err := json.Marshal(c)
if err != nil {
c.Warnf("Unable to encode snapshot: %s", err)
c.l.Warnf("Unable to encode snapshot: %s", err)
return err
}

c.Debugf("Snapshot: %s", string(b))
c.l.Debugf("Snapshot: %s", string(b))

_, err = y.Write(b)
if err != nil {
Expand All @@ -197,7 +196,7 @@ func (c *LinuxContainer) markClean() error {
// It is not written in place because that cannot be done atomically.
err = os.Rename(y.Name(), c.snapshotPath())
if err != nil {
c.Warnf("Unable to rename snapshot in place: %s", err)
c.l.Warnf("Unable to rename snapshot in place: %s", err)
return err
}

Expand Down Expand Up @@ -250,7 +249,7 @@ func (c *LinuxContainer) Run() {

err := c.doDestroy()
if err != nil {
c.Warnf("Error destroying container: %s", err)
c.l.Warnf("Error destroying container: %s", err)
}
}

Expand All @@ -276,7 +275,7 @@ func (c *LinuxContainer) runRequest(r *Request) {

t2 := time.Now()

c.Debugf("took: %.6fs", t2.Sub(t1).Seconds())
c.l.Debugf("took: %.6fs", t2.Sub(t1).Seconds())
}

func (c *LinuxContainer) writeInvalidState(r *Request) {
Expand Down Expand Up @@ -353,7 +352,7 @@ func (c *LinuxContainer) DoCreate(x *Request, req *protocol.CreateRequest) {
}

// Add handle to logger
c.Logger = steno.NewTaggedLogger(c.Logger, map[string]string{"handle": c.Handle})
c.l = steno.NewTaggedLogger(c.l, map[string]string{"handle": c.Handle})

// Override idle timeout if specified
if y := req.GraceTime; y != nil {
Expand Down Expand Up @@ -475,7 +474,7 @@ func (c *LinuxContainer) spawn(a []string, e []string, r io.Reader) (int, error)
w := path.Join(c.ContainerPath(), "jobs", fmt.Sprintf("%d", i))
err := os.MkdirAll(w, 0700)
if err != nil {
c.Warnf("os.MkdirAll: %s", err)
c.l.Warnf("os.MkdirAll: %s", err)
return -1, err
}

Expand All @@ -489,7 +488,7 @@ func (c *LinuxContainer) spawn(a []string, e []string, r io.Reader) (int, error)
Stdin: r,
}

c.Debugf("Spawn: %#v", *j)
c.l.Debugf("Spawn: %#v", *j)

j.Spawn()

Expand Down

0 comments on commit 2be4308

Please sign in to comment.