in main.go [49:103]
func run() error {
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
return errors.Wrap(err, "unable to bind command line flags")
}
globalArgs, err := getGlobalArgs()
if err != nil {
return errors.Wrap(err, "unable to get global arguments")
}
// Read the Windows specific options and set the environment up accordingly
if runtime.GOOS == "windows" {
windowsArgs := getWindowsArgs()
err = setWindowsEnv(windowsArgs.LogFileDir, globalArgs.ContainerName, windowsArgs.ProxyEnvVar)
if err != nil {
return errors.Wrap(err, "failed to set up Windows env with options")
}
defer cleanWindowsEnv(windowsArgs.ProxyEnvVar)
}
debug.Verbose = viper.GetBool(verboseKey)
if debug.Verbose {
debug.SendEventsToLog(logger.DaemonName, "Using verbose mode", debug.INFO, 0)
// If in Verbose mode, start a goroutine to catch os signal and print stack trace
debug.StartStackTraceHandler()
}
// Set UID and/or GID of main goroutine/shim logger process if specified.
// If you are building with go version includes the following commit, you only need
// to call this once in main goroutine. Otherwise you need call this function in all
// goroutines to let this syscall work properly.
// Commit: https://github.com/golang/go/commit/d1b1145cace8b968307f9311ff611e4bb810710c
// TODO: remove the above comment once the changes are released: https://go-review.googlesource.com/c/go/+/210639
if err = logger.SetUIDAndGID(globalArgs.UID, globalArgs.GID); err != nil {
return err
}
logDriver := globalArgs.LogDriver
debug.SendEventsToLog(logger.DaemonName, "Driver: "+logDriver, debug.INFO, 0)
switch logDriver {
case awslogsDriverName:
if err := runAWSLogsDriver(globalArgs); err != nil {
return errors.Wrap(err, "unable to run awslogs driver")
}
case fluentdDriverName:
runFluentdDriver(globalArgs)
case splunkDriverName:
if err := runSplunkDriver(globalArgs); err != nil {
return errors.Wrap(err, "unable to run splunk driver")
}
default:
return errors.Errorf("unknown log driver: %s", logDriver)
}
return nil
}