當前位置: 首頁>>代碼示例>>Golang>>正文


Golang T.Debugf方法代碼示例

本文整理匯總了Golang中github.com/aws/amazon-ssm-agent/agent/log.T.Debugf方法的典型用法代碼示例。如果您正苦於以下問題:Golang T.Debugf方法的具體用法?Golang T.Debugf怎麽用?Golang T.Debugf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/aws/amazon-ssm-agent/agent/log.T的用法示例。


在下文中一共展示了T.Debugf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: MoveCommandState

// MoveCommandState moves the CommandState object
func MoveCommandState(log log.T, commandID, instanceID, srcLocationFolder, dstLocationFolder string) {

	//get a lock for documentID specific lock
	lockDocument(commandID)

	absoluteSource := path.Join(appconfig.DefaultDataStorePath,
		instanceID,
		appconfig.DefaultCommandRootDirName,
		appconfig.DefaultLocationOfState,
		srcLocationFolder)

	absoluteDestination := path.Join(appconfig.DefaultDataStorePath,
		instanceID,
		appconfig.DefaultCommandRootDirName,
		appconfig.DefaultLocationOfState,
		dstLocationFolder)

	if s, err := fileutil.MoveFile(commandID, absoluteSource, absoluteDestination); s && err == nil {
		log.Debugf("moved file %v from %v to %v successfully", commandID, srcLocationFolder, dstLocationFolder)
	} else {
		log.Debugf("moving file %v from %v to %v failed with error %v", commandID, srcLocationFolder, dstLocationFolder, err)
	}

	//release documentID specific lock - before deleting the entry from the map
	unlockDocument(commandID)

	//delete documentID specific lock if document has finished executing. This is to avoid documentLock growing too much in memory.
	//This is done by ensuring that as soon as document finishes executing it is removed from documentLock
	//Its safe to assume that document has finished executing if it is being moved to appconfig.DefaultLocationOfCompleted
	if dstLocationFolder == appconfig.DefaultLocationOfCompleted {
		deleteLock(commandID)
	}
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:34,代碼來源:state_helper.go

示例2: process

// process launches one job in a separate go routine and waits
// for either the job to finish or for a cancel to be requested.
// If cancel is requested, this function waits for some time to allow the
// job to complete. If the job does not complete by the timeout, the go routine
// of the job is abandoned, and this function returns.
func process(log log.T, job Job, cancelFlag *ChanneledCancelFlag, cancelWait time.Duration, clock times.Clock) {
	// Make a buffered channel to avoid blocking on send. This helps
	// in case the job fails to cancel on time and we give up on it.
	// If the job finally ends, it will succeed to send a signal
	// on the channel and then it will terminate. This will allow
	// the garbage collector to collect the go routine's resources
	// and the channel.
	doneChan := make(chan struct{}, 1)

	go runJob(log, func() { job(cancelFlag) }, doneChan)

	done := waitEither(doneChan, cancelFlag.ch)
	if done {
		// task done, set the flag to wake up waiting routines
		cancelFlag.Set(Completed)
		return
	}

	log.Debugf("Execution has been canceled, waiting up to %v to finish", cancelWait)
	done = waitEither(doneChan, clock.After(cancelWait))
	if done {
		// job completed within cancel waiting window
		cancelFlag.Set(Completed)
		return
	}

	log.Debugf("Job failed to terminate within %v!", cancelWait)
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:33,代碼來源:proc.go

示例3: HandleAwsError

// HandleAwsError logs an AWS error.
func HandleAwsError(log log.T, err error, stopPolicy *StopPolicy) {
	if err != nil {
		// notice that we're using 1, so it will actually log the where
		// the error happened, 0 = this function, we don't want that.
		pc, fn, line, _ := runtime.Caller(1)
		log.Debugf("error in %s[%s:%d] %v", runtime.FuncForPC(pc).Name(), fn, line, err)

		// In case this is aws error, update the stop policy as well.
		if aErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			log.Debugf("AWS error. Code: %v, Message: %v, origerror: %v ", aErr.Code(), aErr.Message(), aErr.OrigErr())

			// special treatment for Timeout exception - as this is expected
			if aErr.Code() == "RequestError" && aErr.OrigErr() != nil && strings.Contains(aErr.OrigErr().Error(), "Client.Timeout") {
				// resetting the error count to 0 - as these exceptions are all expected
				if stopPolicy != nil {
					resetStopPolicy(stopPolicy)
				}
				return
			}
		}

		log.Errorf("error when calling AWS APIs. error details - %v", err)
		if stopPolicy != nil {
			log.Infof("increasing error count by 1")
			stopPolicy.AddErrorCount(1)
		}

	} else {
		// there is no error,
		resetStopPolicy(stopPolicy)
	}
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:34,代碼來源:awserr.go

示例4: LatestVersion

// LatestVersion returns latest version for specific package
func (m *Manifest) LatestVersion(log log.T, context *updateutil.InstanceContext, packageName string) (result string, err error) {
	var version = minimumVersion
	var compareResult = 0
	for _, p := range m.Packages {
		if p.Name == packageName {
			for _, f := range p.Files {
				if f.Name == context.FileName(packageName) {
					for _, v := range f.AvailableVersions {
						if compareResult, err = updateutil.VersionCompare(v.Version, version); err != nil {
							return version, err
						}
						if compareResult > 0 {
							version = v.Version
						}
					}
				}
			}
		}
	}
	if version == minimumVersion {
		log.Debugf("Filename: %v", context.FileName(packageName))
		log.Debugf("Package Name: %v", packageName)
		log.Debugf("Manifest: %v", m)
		return version, fmt.Errorf("cannot find the latest version for package %v", packageName)
	}

	return version, nil
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:29,代碼來源:parser.go

示例5: LoadUpdateContext

// LoadUpdateContext loads update context info from local storage, set current update with new update detail
func LoadUpdateContext(log log.T, source string) (context *UpdateContext, err error) {
	log.Debugf("file %v", source)
	if _, err := os.Stat(source); os.IsNotExist(err) {
		log.Debugf("UpdateContext file doesn't exist, creating new one")
		context = &UpdateContext{}
	} else {
		log.Debugf("UpdateContext file exists")
		if context, err = parseContext(log, source); err != nil {
			return context, err
		}
	}
	return context, nil
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:14,代碼來源:context.go

示例6: getPlatformDetail

func getPlatformDetail(log log.T, param string) (value string, err error) {
	var contentsBytes []byte
	value = notAvailableMessage

	log.Debugf(gettingPlatformDetailsMessage)
	if contentsBytes, err = exec.Command(platformDetailsCommand, param).Output(); err != nil {
		log.Debugf(errorOccurredMessage, platformDetailsCommand, err)
		return
	}
	value = strings.TrimSpace(string(contentsBytes))
	log.Debugf(commandOutputMessage, value)
	return
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:13,代碼來源:platform_darwin.go

示例7: uploadOutput

// uploadOutput uploads the stdout and stderr file to S3
func (c *contextManager) uploadOutput(log log.T, context *UpdateContext) (err error) {

	awsConfig := sdkutil.AwsConfig()
	var config appconfig.SsmagentConfig
	config, err = appconfig.Config(false)

	if err != nil {
		return fmt.Errorf("could not load config file: %v", err)
	}
	// If customers have provided override in app config, honor that.
	if config.S3.Region != "" {
		awsConfig.Region = &config.S3.Region
	}
	log.Infof("Uploading output files to region: %v", *awsConfig.Region)

	s3 := s3.New(session.New(awsConfig))

	// upload outputs (if any) to s3
	uploader := s3util.NewManager(s3)
	uploadOutputsToS3 := func() {
		// delete temp outputDir once we're done
		defer pluginutil.DeleteDirectory(log, updateutil.UpdateOutputDirectory(context.Current.UpdateRoot))

		// get stdout file path
		stdoutPath := updateutil.UpdateStandOutPath(context.Current.UpdateRoot, context.Current.StdoutFileName)
		s3Key := path.Join(context.Current.OutputS3KeyPrefix, context.Current.StdoutFileName)
		log.Debugf("Uploading %v to s3://%v/%v", stdoutPath, context.Current.OutputS3BucketName, s3Key)
		err = uploader.S3Upload(context.Current.OutputS3BucketName, s3Key, stdoutPath)
		if err != nil {
			log.Errorf("failed uploading %v to s3://%v/%v \n err:%v",
				stdoutPath,
				context.Current.OutputS3BucketName,
				s3Key,
				err)
		}

		// get stderr file path
		stderrPath := updateutil.UpdateStandOutPath(context.Current.UpdateRoot, context.Current.StderrFileName)
		s3Key = path.Join(context.Current.OutputS3KeyPrefix, context.Current.StderrFileName)
		log.Debugf("Uploading %v to s3://%v/%v", stderrPath, context.Current.OutputS3BucketName, s3Key)
		err = uploader.S3Upload(context.Current.OutputS3BucketName, s3Key, stderrPath)
		if err != nil {
			log.Errorf("failed uploading %v to s3://%v/%v \n err:%v", stderrPath, context.Current.StderrFileName, s3Key, err)
		}
	}

	uploadOutputsToS3()

	return nil
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:51,代碼來源:context.go

示例8: setMsiExecStatus

// setMsiExecStatus sets the exit status and output to be returned to the user based on exit code
func setMsiExecStatus(log log.T, pluginInput ApplicationPluginInput, cancelFlag task.CancelFlag, out *ApplicationPluginOutput) {
	out.Stdout = pluginInput.Source
	out.Stderr = ""
	out.Status = contracts.ResultStatusFailed
	isUnKnownError := false

	switch out.ExitCode {
	case appconfig.SuccessExitCode:
		out.Status = contracts.ResultStatusSuccess
	case ErrorUnknownProduct:
		if pluginInput.Action == UNINSTALL {
			// Uninstall will skip, if product is not currently installed.
			// This is needed to support idempotent behavior.
			out.Status = contracts.ResultStatusSuccess
		}
	case ErrorSuccessRebootInitiated:
		fallthrough
	case appconfig.RebootExitCode:
		out.Status = contracts.ResultStatusSuccessAndReboot
	case pluginutil.CommandStoppedPreemptivelyExitCode:
		if cancelFlag.ShutDown() {
			out.Status = contracts.ResultStatusFailed
		}
		if cancelFlag.Canceled() {
			out.Status = contracts.ResultStatusCancelled
		}
		out.Status = contracts.ResultStatusTimedOut
	default:
		isUnKnownError = true
	}

	if isUnKnownError {
		// Note: Sample Stderr:
		// Action:{Installed}; Status:{Failed};
		// ErrorCode:{1620}; ErrorMsg:{ERROR_INSTALL_PACKAGE_INVALID};
		// Description:{This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package.};
		// Source:{https:///}

		// Construct stderr in above format using StandardMsiErrorCodes
		out.Stderr = fmt.Sprintf("Action:{%v}; Status:{%v}; ErrorCode:{%v}; %v Source:{%v};", pluginInput.Action, out.Status, out.ExitCode, getExitCodeDescription(out.ExitCode), pluginInput.Source)
	}

	// Logging msiexec.Result
	log.Debug("logging stdouts & errors after setting final status for msiexec")
	log.Debugf("resultCode: %v", out.ExitCode)
	log.Debugf("stdout: %v", out.Stdout)
	log.Debugf("stderr: %v", out.Stderr)
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:49,代碼來源:msiexec.go

示例9: setCmdState

// setCmdState persists given commandState
func setCmdState(log log.T, commandState message.CommandState, absoluteFileName, locationFolder string) {

	content, err := jsonutil.Marshal(commandState)
	if err != nil {
		log.Errorf("encountered error with message %v while marshalling %v to string", err, commandState)
	} else {
		if fileutil.Exists(absoluteFileName) {
			log.Debugf("overwriting contents of %v", absoluteFileName)
		}
		log.Tracef("persisting interim state %v in file %v", jsonutil.Indent(content), absoluteFileName)
		if s, err := fileutil.WriteIntoFileWithPermissions(absoluteFileName, jsonutil.Indent(content), os.FileMode(int(appconfig.ReadWriteAccess))); s && err == nil {
			log.Debugf("successfully persisted interim state in %v", locationFolder)
		} else {
			log.Debugf("persisting interim state in %v failed with error %v", locationFolder, err)
		}
	}
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:18,代碼來源:state_helper.go

示例10: GetS3BucketRegionFromErrorMsg

// GetS3BucketRegionFromErrorMsg gets the expected region from the error message
func (m *Manager) GetS3BucketRegionFromErrorMsg(log log.T, errMsg string) string {
	var expectedBucketRegion = ""
	if errMsg != "" && m.IsS3ErrorRelatedToWrongBucketRegion(errMsg) {
		//Sample error message:
		//AuthorizationHeaderMalformed: The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'us-west-2' status code: 400, request id: []
		splitResult := strings.Split(errMsg, ";")
		furtherSplitResult := strings.Split(splitResult[len(splitResult)-1], "'")
		expectedBucketRegion = furtherSplitResult[1]
		log.Debugf("expected region according to error message = %v", expectedBucketRegion)

		if expectedBucketRegion == "" {
			log.Debugf("Setting expected region = us-east-1 as per http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGETlocation.html")
			expectedBucketRegion = "us-east-1"
		}
	}
	return expectedBucketRegion
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:18,代碼來源:s3util.go

示例11: DownloadFileFromSource

// DownloadFileFromSource downloads file from source
func DownloadFileFromSource(log log.T, source string, sourceHash string, sourceHashType string) (artifact.DownloadOutput, error) {
	// download source and verify its integrity
	downloadInput := artifact.DownloadInput{
		SourceURL:       source,
		SourceHashValue: sourceHash,
		SourceHashType:  sourceHashType,
	}
	log.Debugf("Downloading file %v", downloadInput)
	return artifact.Download(log, downloadInput)
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:11,代碼來源:pluginutil.go

示例12: RemoveData

// RemoveData deletes the fileName from locationFolder under defaultLogDir/instanceID
func RemoveData(log log.T, commandID, instanceID, locationFolder string) {

	absoluteFileName := getCmdStateFileName(commandID, instanceID, locationFolder)

	err := fileutil.DeleteFile(absoluteFileName)
	if err != nil {
		log.Errorf("encountered error %v while deleting file %v", err, absoluteFileName)
	} else {
		log.Debugf("successfully deleted file %v", absoluteFileName)
	}
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:12,代碼來源:state_helper.go

示例13: runCommandsRawInput

// runCommandsRawInput executes one set of commands and returns their output.
// The input is in the default json unmarshal format (e.g. map[string]interface{}).
func (p *Plugin) runCommandsRawInput(log log.T, rawPluginInput interface{}, orchestrationDirectory string, cancelFlag task.CancelFlag, outputS3BucketName string, outputS3KeyPrefix string) (out ApplicationPluginOutput) {
	var pluginInput ApplicationPluginInput
	err := jsonutil.Remarshal(rawPluginInput, &pluginInput)
	log.Debugf("Plugin input %v", pluginInput)
	if err != nil {
		errorString := fmt.Errorf("Invalid format in plugin properties %v;\nerror %v", rawPluginInput, err)
		out.MarkAsFailed(log, errorString)
		return
	}
	return p.runCommands(log, pluginInput, orchestrationDirectory, cancelFlag, outputS3BucketName, outputS3KeyPrefix)
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:13,代碼來源:application.go

示例14: PersistData

// PersistData stores the given object in the file-system in pretty Json indented format
// This will override the contents of an already existing file
func PersistData(log log.T, commandID, instanceID, locationFolder string, object interface{}) {

	lockDocument(commandID)
	defer unlockDocument(commandID)

	absoluteFileName := getCmdStateFileName(commandID, instanceID, locationFolder)

	content, err := jsonutil.Marshal(object)
	if err != nil {
		log.Errorf("encountered error with message %v while marshalling %v to string", err, object)
	} else {
		if fileutil.Exists(absoluteFileName) {
			log.Debugf("overwriting contents of %v", absoluteFileName)
		}
		log.Tracef("persisting interim state %v in file %v", jsonutil.Indent(content), absoluteFileName)
		if s, err := fileutil.WriteIntoFileWithPermissions(absoluteFileName, jsonutil.Indent(content), os.FileMode(int(appconfig.ReadWriteAccess))); s && err == nil {
			log.Debugf("successfully persisted interim state in %v", locationFolder)
		} else {
			log.Debugf("persisting interim state in %v failed with error %v", locationFolder, err)
		}
	}
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:24,代碼來源:state_helper.go

示例15: isErrorUnexpected

// isErrorUnexpected processes GetMessages errors and determines if its unexpected error
func isErrorUnexpected(log log.T, err error, requestTime, responseTime time.Time) bool {
	//determine the time it took for the api to respond
	timeDiff := responseTime.Sub(requestTime).Seconds()
	//check if response isn't coming too quick & if error is unexpected
	if timeDiff < QuickResponseThreshold {
		//response was too quick - this is unexpected
		return true
	}

	//response wasn't too quick
	//checking if the class of errors are expected
	if isServerBasedError(err.Error()) {
		log.Debugf("server terminated connection after %v seconds - this is expected in long polling api calls.", timeDiff)
		return false
	} else if isClientBasedError(err.Error()) {
		log.Debugf("client terminated connection after %v seconds - this is expected in long polling api calls.", timeDiff)
		return false
	} else {
		//errors are truly unexpected
		return true
	}
}
開發者ID:aws,項目名稱:amazon-ssm-agent,代碼行數:23,代碼來源:service.go


注:本文中的github.com/aws/amazon-ssm-agent/agent/log.T.Debugf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。