Move call logger to a separate backend (more backends to come)

This commit is contained in:
Solomon Hykes 2014-05-01 16:29:16 -07:00
parent ca7c1fbf49
commit cd9abab36a
2 changed files with 35 additions and 14 deletions

30
backends/debug.go Normal file
View File

@ -0,0 +1,30 @@
package backends
import (
"fmt"
"github.com/dotcloud/docker/engine"
"strings"
)
func Debug() engine.Installer {
return &debug{}
}
type debug struct {
}
func (d *debug) Install(eng *engine.Engine) error {
eng.RegisterCatchall(func(job *engine.Job) engine.Status {
fmt.Printf("--> %s %s\n", job.Name, strings.Join(job.Args, " "))
for k, v := range job.Env().Map() {
fmt.Printf(" %s=%s\n", k, v)
}
// This helps us detect the race condition if our time.Sleep
// missed it. (see comment in main)
if job.Name == "acceptconnections" {
panic("race condition in github.com/dotcloud/docker/api/server/ServeApi")
}
return engine.StatusOK
})
return nil
}

View File

@ -1,29 +1,20 @@
package main package main
import ( import (
"fmt"
"github.com/docker/swarmd/backends"
"github.com/dotcloud/docker/api/server" "github.com/dotcloud/docker/api/server"
"github.com/dotcloud/docker/engine" "github.com/dotcloud/docker/engine"
"strings"
"os" "os"
"fmt"
"time" "time"
) )
func main() { func main() {
eng := engine.New() eng := engine.New()
eng.Logging = false eng.Logging = false
eng.RegisterCatchall(func(job *engine.Job) engine.Status { if err := backends.Debug().Install(eng); err != nil {
fmt.Printf("--> %s %s\n", job.Name, strings.Join(job.Args, " ")) Fatalf("%v", err)
for k, v := range job.Env().Map() {
fmt.Printf(" %s=%s\n", k, v)
} }
// This helps us detect the race condition if our time.Sleep
// missed it. (see comment below)
if job.Name == "acceptconnections" {
panic("race condition in github.com/dotcloud/docker/api/server/ServeApi")
}
return engine.StatusOK
})
eng.Register(os.Args[0], server.ServeApi) eng.Register(os.Args[0], server.ServeApi)
// Register the entrypoint job as the current proces command name, // Register the entrypoint job as the current proces command name,