func run()

in main.go [40:94]


func run() error {
	if err := viper.BindPFlags(pflag.CommandLine); err != nil {
		return fmt.Errorf("unable to bind command line flags: %w", err)
	}

	globalArgs, err := getGlobalArgs()
	if err != nil {
		return fmt.Errorf("unable to get global arguments: %w", err)
	}

	// 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 fmt.Errorf("failed to set up Windows env with options: %w", err)
		}
		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 fmt.Errorf("unable to run awslogs driver: %w", err)
		}
	case fluentdDriverName:
		runFluentdDriver(globalArgs)
	case splunkDriverName:
		if err := runSplunkDriver(globalArgs); err != nil {
			return fmt.Errorf("unable to run splunk driver: %w", err)
		}
	default:
		return fmt.Errorf("unknown log driver: %s", logDriver)
	}

	return nil
}