func main()

in integration/example/cmd/main.go [90:133]


func main() {
	ctx := context.Background()
	lp := log.Parameters{
		OSType:     runtime.GOOS,
		Level:      zapcore.InfoLevel,
		LogToCloud: true,
	}

	cloudProps := &cpb.CloudProperties{}
	if cp := metadataserver.FetchCloudProperties(); cp != nil {
		cloudProps = &cpb.CloudProperties{
			ProjectId:        cp.ProjectID,
			InstanceId:       cp.InstanceID,
			Zone:             cp.Zone,
			InstanceName:     cp.InstanceName,
			Image:            cp.Image,
			NumericProjectId: cp.NumericProjectID,
			MachineType:      cp.MachineType,
		}
	}
	lp.CloudLoggingClient = log.CloudLoggingClient(ctx, cloudProps.GetProjectId())
	registerSubCommands(ctx, lp, cloudProps)

	rc := 0
	if err := rootCmd.ExecuteContext(ctx); err != nil {
		log.Logger.Error(err)
		rc = 1
	}

	// Defer cloud log flushing to ensure execution on any exit from main.
	defer func() {
		if lp.CloudLoggingClient != nil {
			flushTimer := time.AfterFunc(5*time.Second, func() {
				log.Logger.Error("Cloud logging client failed to flush logs within the 5-second deadline, exiting.")
				os.Exit(rc)
			})
			log.FlushCloudLog()
			lp.CloudLoggingClient.Close()
			flushTimer.Stop()
		}
	}()

	os.Exit(rc)
}