Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Oct 2, 2015
1 parent d531085 commit 62ca510
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cli/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"github.com/fsouza/go-dockerclient"
"github.com/mcuadros/ofelia/core"
"github.com/mcuadros/ofelia/middlewares"
"github.com/op/go-logging"
)

// DaemonCommand daemon process
Expand Down Expand Up @@ -50,9 +52,11 @@ func (c *DaemonCommand) boot() error {
return err
}

logger := c.buildLogger()
c.scheduler = core.NewScheduler()
for _, j := range c.config.Jobs {
j.Client = d
j.Use(logger)
c.scheduler.AddJob(j)
}

Expand Down Expand Up @@ -91,3 +95,12 @@ func (c *DaemonCommand) shutdown() error {
fmt.Println("Waiting running jobs.")
return c.scheduler.Stop()
}

const logFormat = "%{color}%{shortfile} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}"

func (c *DaemonCommand) buildLogger() *middlewares.Logger {
logging.SetFormatter(logging.MustStringFormatter(logFormat))

return middlewares.NewLogger(logging.MustGetLogger("ofelia"))

}
1 change: 1 addition & 0 deletions core/execjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (j *ExecJob) startExec(e *Execution, exec *docker.Exec) error {

func (j *ExecJob) inspectExec(exec *docker.Exec) error {
i, err := j.Client.InspectExec(exec.ID)

if err != nil {
return fmt.Errorf("error inspecting exec: %s", err)
}
Expand Down

0 comments on commit 62ca510

Please sign in to comment.