summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--runsc/boot/config.go7
-rw-r--r--runsc/main.go19
-rw-r--r--runsc/sandbox/sandbox.go6
-rw-r--r--runsc/specutils/specutils.go25
-rwxr-xr-xrunsc/test/install.sh2
6 files changed, 35 insertions, 26 deletions
diff --git a/README.md b/README.md
index d85948ce5..a4fca1f62 100644
--- a/README.md
+++ b/README.md
@@ -297,7 +297,7 @@ Docker configuration (`/etc/docker/daemon.json`):
"runsc": {
"path": "/usr/local/bin/runsc",
"runtimeArgs": [
- "--debug-log-dir=/tmp/runsc",
+ "--debug-log=/tmp/runsc/",
"--debug",
"--strace"
]
diff --git a/runsc/boot/config.go b/runsc/boot/config.go
index cd977c8a5..41af084b9 100644
--- a/runsc/boot/config.go
+++ b/runsc/boot/config.go
@@ -160,9 +160,8 @@ type Config struct {
// LogFormat is the log format, "text" or "json".
LogFormat string
- // DebugLogDir is the directory to log debug information to, if not
- // empty.
- DebugLogDir string
+ // DebugLog is the path to log debug information to, if not empty.
+ DebugLog string
// FileAccess indicates how the filesystem is accessed.
FileAccess FileAccessType
@@ -217,7 +216,7 @@ func (c *Config) ToFlags() []string {
"--debug=" + strconv.FormatBool(c.Debug),
"--log=" + c.LogFilename,
"--log-format=" + c.LogFormat,
- "--debug-log-dir=" + c.DebugLogDir,
+ "--debug-log=" + c.DebugLog,
"--file-access=" + c.FileAccess.String(),
"--overlay=" + strconv.FormatBool(c.Overlay),
"--network=" + c.Network.String(),
diff --git a/runsc/main.go b/runsc/main.go
index 16d30f7a0..27aec1cd9 100644
--- a/runsc/main.go
+++ b/runsc/main.go
@@ -45,10 +45,10 @@ var (
// system that are not covered by the runtime spec.
// Debugging flags.
- debugLogDir = flag.String("debug-log-dir", "", "additional location for logs. It creates individual log files per command")
- logPackets = flag.Bool("log-packets", false, "enable network packet logging")
- logFD = flag.Int("log-fd", -1, "file descriptor to log to. If set, the 'log' flag is ignored.")
- debugLogFD = flag.Int("debug-log-fd", -1, "file descriptor to write debug logs to. If set, the 'debug-log-dir' flag is ignored.")
+ debugLog = flag.String("debug-log", "", "additional location for logs. If it ends with '/', log files are created inside the directory with default names. The following variables are available: %TIMESTAMP%, %COMMAND%.")
+ logPackets = flag.Bool("log-packets", false, "enable network packet logging")
+ logFD = flag.Int("log-fd", -1, "file descriptor to log to. If set, the 'log' flag is ignored.")
+ debugLogFD = flag.Int("debug-log-fd", -1, "file descriptor to write debug logs to. If set, the 'debug-log-dir' flag is ignored.")
// Debugging flags: strace related
strace = flag.Bool("strace", false, "enable strace")
@@ -131,7 +131,7 @@ func main() {
Debug: *debug,
LogFilename: *logFilename,
LogFormat: *logFormat,
- DebugLogDir: *debugLogDir,
+ DebugLog: *debugLog,
FileAccess: fsAccess,
Overlay: *overlay,
Network: netType,
@@ -195,13 +195,10 @@ func main() {
}
e = log.MultiEmitter{e, log.GoogleEmitter{&log.Writer{Next: f}}}
- } else if *debugLogDir != "" {
- if err := os.MkdirAll(*debugLogDir, 0775); err != nil {
- cmd.Fatalf("error creating dir %q: %v", *debugLogDir, err)
- }
- f, err := specutils.DebugLogFile(*debugLogDir, subcommand)
+ } else if *debugLog != "" {
+ f, err := specutils.DebugLogFile(*debugLog, subcommand)
if err != nil {
- cmd.Fatalf("error opening debug log file in %q: %v", *debugLogDir, err)
+ cmd.Fatalf("error opening debug log file in %q: %v", *debugLog, err)
}
e = log.MultiEmitter{e, log.GoogleEmitter{&log.Writer{Next: f}}}
}
diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go
index 37a3efd09..a0de4a175 100644
--- a/runsc/sandbox/sandbox.go
+++ b/runsc/sandbox/sandbox.go
@@ -291,10 +291,10 @@ func (s *Sandbox) createSandboxProcess(spec *specs.Spec, conf *boot.Config, bund
cmd.Args = append(cmd.Args, "--log-fd="+strconv.Itoa(nextFD))
nextFD++
}
- if conf.DebugLogDir != "" {
- debugLogFile, err := specutils.DebugLogFile(conf.DebugLogDir, "boot")
+ if conf.DebugLog != "" {
+ debugLogFile, err := specutils.DebugLogFile(conf.DebugLog, "boot")
if err != nil {
- return fmt.Errorf("error opening debug log file in %q: %v", conf.DebugLogDir, err)
+ return fmt.Errorf("error opening debug log file in %q: %v", conf.DebugLog, err)
}
defer debugLogFile.Close()
cmd.ExtraFiles = append(cmd.ExtraFiles, debugLogFile)
diff --git a/runsc/specutils/specutils.go b/runsc/specutils/specutils.go
index ac017ba2d..6b3e52021 100644
--- a/runsc/specutils/specutils.go
+++ b/runsc/specutils/specutils.go
@@ -351,12 +351,25 @@ func WaitForReady(pid int, timeout time.Duration, ready func() (bool, error)) er
return backoff.Retry(op, b)
}
-// DebugLogFile opens a file in logDir based on the timestamp and subcommand
-// for writing.
-func DebugLogFile(logDir, subcommand string) (*os.File, error) {
- // Format: <debug-log-dir>/runsc.log.<yyyymmdd-hhmmss.uuuuuu>.<command>
- filename := fmt.Sprintf("runsc.log.%s.%s", time.Now().Format("20060102-150405.000000"), subcommand)
- return os.OpenFile(filepath.Join(logDir, filename), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0664)
+// DebugLogFile opens a log file using 'logPattern' as location. If 'logPattern'
+// ends with '/', it's used as a directory with default file name.
+// 'logPattern' can contain variables that are substitued:
+// - %TIMESTAMP%: is replaced with a timestamp using the following format:
+// <yyyymmdd-hhmmss.uuuuuu>
+// - %COMMAND%: is replaced with 'command'
+func DebugLogFile(logPattern, command string) (*os.File, error) {
+ if strings.HasSuffix(logPattern, "/") {
+ // Default format: <debug-log>/runsc.log.<yyyymmdd-hhmmss.uuuuuu>.<command>
+ logPattern += "runsc.log.%TIMESTAMP%.%COMMAND%"
+ }
+ logPattern = strings.Replace(logPattern, "%TIMESTAMP%", time.Now().Format("20060102-150405.000000"), -1)
+ logPattern = strings.Replace(logPattern, "%COMMAND%", command, -1)
+
+ dir := filepath.Dir(logPattern)
+ if err := os.MkdirAll(dir, 0775); err != nil {
+ return nil, fmt.Errorf("error creating dir %q: %v", dir, err)
+ }
+ return os.OpenFile(logPattern, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0664)
}
// Mount creates the mount point and calls Mount with the given flags.
diff --git a/runsc/test/install.sh b/runsc/test/install.sh
index c110d96f9..c239588d4 100755
--- a/runsc/test/install.sh
+++ b/runsc/test/install.sh
@@ -75,7 +75,7 @@ if [[ ${uninstall} == 0 ]]; then
mkdir -p "${logdir}"
sudo -n chmod a+wx "${logdir}"
- declare -r args="--debug-log-dir "${logdir}" --debug --strace --log-packets"
+ declare -r args="--debug-log '${logdir}/' --debug --strace --log-packets"
sudo -n "${dockercfg}" runtime-add "${runtime}" "${runsc}" ${args}
sudo -n "${dockercfg}" runtime-add "${runtime}"-kvm "${runsc}" --platform=kvm ${args}
sudo -n "${dockercfg}" runtime-add "${runtime}"-hostnet "${runsc}" --network=host ${args}