Merge pull request #25 from runcom/debug-logrus
server: add debug to ocid
This commit is contained in:
commit
5e672974ff
1 changed files with 38 additions and 0 deletions
|
@ -1,10 +1,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/kubernetes-incubator/ocid/server"
|
"github.com/kubernetes-incubator/ocid/server"
|
||||||
"github.com/kubernetes/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
"github.com/kubernetes/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -36,6 +38,42 @@ func main() {
|
||||||
Value: "/var/lib/ocid/containers",
|
Value: "/var/lib/ocid/containers",
|
||||||
Usage: "ocid container dir",
|
Usage: "ocid container dir",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "debug",
|
||||||
|
Usage: "enable debug output for logging",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "log",
|
||||||
|
Value: "",
|
||||||
|
Usage: "set the log file path where internal debug information is written",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "log-format",
|
||||||
|
Value: "text",
|
||||||
|
Usage: "set the format used by logs ('text' (default), or 'json')",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Before = func(c *cli.Context) error {
|
||||||
|
if c.GlobalBool("debug") {
|
||||||
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
|
}
|
||||||
|
if path := c.GlobalString("log"); path != "" {
|
||||||
|
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_SYNC, 0666)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logrus.SetOutput(f)
|
||||||
|
}
|
||||||
|
switch c.GlobalString("log-format") {
|
||||||
|
case "text":
|
||||||
|
// retain logrus's default.
|
||||||
|
case "json":
|
||||||
|
logrus.SetFormatter(new(logrus.JSONFormatter))
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown log-format %q", c.GlobalString("log-format"))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Action = func(c *cli.Context) error {
|
app.Action = func(c *cli.Context) error {
|
||||||
|
|
Loading…
Reference in a new issue