mirror of
https://github.com/moby/moby.git
synced 2025-07-29 07:21:35 +03:00
Add --log-level support
Next steps, in another PR, would be: - make all logging go through the logrus stuff - I'd like to see if we can remove the env var stuff (like DEBUG) but we'll see Closes #5198 Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@ -223,3 +224,63 @@ func TestDaemonIptablesCreate(t *testing.T) {
|
||||
|
||||
logDone("daemon - run,iptables - iptables rules for always restarted container created after daemon restart")
|
||||
}
|
||||
|
||||
func TestDaemonLoggingLevel(t *testing.T) {
|
||||
d := NewDaemon(t)
|
||||
|
||||
if err := d.Start("--log-level=bogus"); err == nil {
|
||||
t.Fatal("Daemon should not have been able to start")
|
||||
}
|
||||
|
||||
d = NewDaemon(t)
|
||||
if err := d.Start("--log-level=debug"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d.Stop()
|
||||
content, _ := ioutil.ReadFile(d.logFile.Name())
|
||||
if !strings.Contains(string(content), `level="debug"`) {
|
||||
t.Fatalf(`Missing level="debug" in log file:\n%s`, string(content))
|
||||
}
|
||||
|
||||
d = NewDaemon(t)
|
||||
if err := d.Start("--log-level=fatal"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d.Stop()
|
||||
content, _ = ioutil.ReadFile(d.logFile.Name())
|
||||
if strings.Contains(string(content), `level="debug"`) {
|
||||
t.Fatalf(`Should not have level="debug" in log file:\n%s`, string(content))
|
||||
}
|
||||
|
||||
d = NewDaemon(t)
|
||||
if err := d.Start("-D"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d.Stop()
|
||||
content, _ = ioutil.ReadFile(d.logFile.Name())
|
||||
if !strings.Contains(string(content), `level="debug"`) {
|
||||
t.Fatalf(`Missing level="debug" in log file using -D:\n%s`, string(content))
|
||||
}
|
||||
|
||||
d = NewDaemon(t)
|
||||
if err := d.Start("--debug"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d.Stop()
|
||||
content, _ = ioutil.ReadFile(d.logFile.Name())
|
||||
if !strings.Contains(string(content), `level="debug"`) {
|
||||
t.Fatalf(`Missing level="debug" in log file using --debug:\n%s`, string(content))
|
||||
}
|
||||
|
||||
d = NewDaemon(t)
|
||||
if err := d.Start("--debug", "--log-level=fatal"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d.Stop()
|
||||
content, _ = ioutil.ReadFile(d.logFile.Name())
|
||||
if !strings.Contains(string(content), `level="debug"`) {
|
||||
t.Fatalf(`Missing level="debug" in log file when using both --debug and --log-level=fatal:\n%s`, string(content))
|
||||
}
|
||||
|
||||
logDone("daemon - Logging Level")
|
||||
}
|
||||
|
Reference in New Issue
Block a user