Add alsologtostderr option

When set sends log messages to the error log:

sudo ./runsc --logtostderr do ls
I0531 17:59:58.105064  144564 x:0] ***************************
I0531 17:59:58.105087  144564 x:0] Args: [runsc --logtostderr do ls]
I0531 17:59:58.105112  144564 x:0] PID: 144564
I0531 17:59:58.105125  144564 x:0] UID: 0, GID: 0
[...]

PiperOrigin-RevId: 251964377
This commit is contained in:
Fabricio Voznika 2019-06-06 17:48:53 -07:00 committed by Shentubot
parent 9ea248489b
commit 2e43dcb26b
1 changed files with 10 additions and 5 deletions

View File

@ -48,11 +48,12 @@ var (
// system that are not covered by the runtime spec.
// Debugging flags.
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.")
debugLogFormat = flag.String("debug-log-format", "text", "log format: text (default), json, or json-k8s")
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.")
debugLogFormat = flag.String("debug-log-format", "text", "log format: text (default), json, or json-k8s")
alsoLogToStderr = flag.Bool("alsologtostderr", false, "send log messages to stderr")
// Debugging flags: strace related
strace = flag.Bool("strace", false, "enable strace")
@ -228,6 +229,10 @@ func main() {
e = newEmitter("text", ioutil.Discard)
}
if *alsoLogToStderr {
e = log.MultiEmitter{e, newEmitter(*debugLogFormat, os.Stderr)}
}
log.SetTarget(e)
log.Infof("***************************")