logging: Add function to handle external loggers

Created a new `setExternalLogger()` which sets (or resets) the logger
used by the external packages which allow a logger to be specified.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
James O. D. Hunt 2018-07-04 14:48:43 +01:00
parent 79e8da0675
commit 03d4d4937c

View File

@ -187,6 +187,16 @@ func setupSignalHandler() {
}() }()
} }
// setExternalLoggers registers the specified logger with the external
// packages which accept a logger to handle their own logging.
func setExternalLoggers(logger *logrus.Entry) {
// Set virtcontainers logger.
vci.SetLogger(logger)
// Set the OCI package logger.
oci.SetLogger(logger)
}
// beforeSubcommands is the function to perform preliminary checks // beforeSubcommands is the function to perform preliminary checks
// before command-line parsing occurs. // before command-line parsing occurs.
func beforeSubcommands(context *cli.Context) error { func beforeSubcommands(context *cli.Context) error {
@ -225,11 +235,7 @@ func beforeSubcommands(context *cli.Context) error {
return fmt.Errorf("unknown log-format %q", context.GlobalString("log-format")) return fmt.Errorf("unknown log-format %q", context.GlobalString("log-format"))
} }
// Set virtcontainers logger. setExternalLoggers(kataLog)
vci.SetLogger(kataLog)
// Set the OCI package logger.
oci.SetLogger(kataLog)
ignoreLogging := false ignoreLogging := false