本文整理汇总了Golang中github.com/Sirupsen/logrus.Logger.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Error方法的具体用法?Golang Logger.Error怎么用?Golang Logger.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Sirupsen/logrus.Logger
的用法示例。
在下文中一共展示了Logger.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: stackLambdaResources
func stackLambdaResources(serviceName string, cf *cloudformation.CloudFormation, logger *logrus.Logger) (provisionedResources, error) {
resources := make(provisionedResources, 0)
nextToken := ""
for {
params := &cloudformation.ListStackResourcesInput{
StackName: aws.String(serviceName),
}
if "" != nextToken {
params.NextToken = aws.String(nextToken)
}
resp, err := cf.ListStackResources(params)
if err != nil {
logger.Error(err.Error())
return nil, err
}
for _, eachSummary := range resp.StackResourceSummaries {
if *eachSummary.ResourceType == "AWS::Lambda::Function" {
resources = append(resources, eachSummary)
}
}
if nil != resp.NextToken {
nextToken = *resp.NextToken
} else {
break
}
}
return resources, nil
}
示例2: Execute
// Execute creates an HTTP listener to dispatch execution. Typically
// called via Main() via command line arguments.
func Execute(lambdaAWSInfos []*LambdaAWSInfo, port int, parentProcessPID int, logger *logrus.Logger) error {
if port <= 0 {
port = defaultHTTPPort
}
logger.Info("Execute!")
lookupMap := make(dispatchMap, 0)
for _, eachLambdaInfo := range lambdaAWSInfos {
lookupMap[eachLambdaInfo.lambdaFnName] = eachLambdaInfo
}
server := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: &lambdaHandler{lookupMap, logger},
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
if 0 != parentProcessPID {
logger.Debug("Sending SIGUSR2 to parent process: ", parentProcessPID)
syscall.Kill(parentProcessPID, syscall.SIGUSR2)
}
logger.Debug("Binding to port: ", port)
err := server.ListenAndServe()
if err != nil {
logger.Error("FAILURE: " + err.Error())
return err
}
logger.Debug("Server available at: ", port)
return nil
}
示例3: safeMergeTemplates
func safeMergeTemplates(sourceTemplate *gocf.Template, destTemplate *gocf.Template, logger *logrus.Logger) error {
var mergeErrors []string
// Append the custom resources
for eachKey, eachLambdaResource := range sourceTemplate.Resources {
_, exists := destTemplate.Resources[eachKey]
if exists {
errorMsg := fmt.Sprintf("Duplicate CloudFormation resource name: %s", eachKey)
mergeErrors = append(mergeErrors, errorMsg)
} else {
destTemplate.Resources[eachKey] = eachLambdaResource
}
}
// Append the custom outputs
for eachKey, eachLambdaOutput := range sourceTemplate.Outputs {
_, exists := destTemplate.Outputs[eachKey]
if exists {
errorMsg := fmt.Sprintf("Duplicate CloudFormation output key name: %s", eachKey)
mergeErrors = append(mergeErrors, errorMsg)
} else {
destTemplate.Outputs[eachKey] = eachLambdaOutput
}
}
if len(mergeErrors) > 0 {
logger.Error("Failed to update template. The following collisions were found:")
for _, eachError := range mergeErrors {
logger.Error("\t" + eachError)
}
return errors.New("Template merge failed")
}
return nil
}
示例4: echoSESEvent
////////////////////////////////////////////////////////////////////////////////
// SES handler
//
func echoSESEvent(event *json.RawMessage,
context *sparta.LambdaContext,
w http.ResponseWriter,
logger *logrus.Logger) {
logger.WithFields(logrus.Fields{
"RequestID": context.AWSRequestID,
}).Info("Request received")
configuration, configErr := sparta.Discover()
logger.WithFields(logrus.Fields{
"Error": configErr,
"Configuration": configuration,
}).Info("Discovery results")
// The message bucket is an explicit `DependsOn` relationship, so it'll be in the
// resources map. We'll find it by looking for the dependent resource with the "AWS::S3::Bucket" type
bucketName := ""
for _, eachResource := range configuration.Resources {
if eachResource.Properties[sparta.TagResourceType] == "AWS::S3::Bucket" {
bucketName = eachResource.Properties["Ref"]
}
}
if "" == bucketName {
logger.Error("Failed to discover SES bucket from sparta.Discovery")
http.Error(w, "Failed to discovery SES MessageBodyBucket", http.StatusInternalServerError)
}
// The bucket is in the configuration map, prefixed by
// SESMessageStoreBucket
var lambdaEvent spartaSES.Event
err := json.Unmarshal([]byte(*event), &lambdaEvent)
if err != nil {
logger.Error("Failed to unmarshal event data: ", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
}
// Get the metdata about the item...
svc := s3.New(session.New())
for _, eachRecord := range lambdaEvent.Records {
logger.WithFields(logrus.Fields{
"Source": eachRecord.SES.Mail.Source,
"MessageID": eachRecord.SES.Mail.MessageID,
"BucketName": bucketName,
}).Info("SES Event")
if "" != bucketName {
params := &s3.HeadObjectInput{
Bucket: aws.String(bucketName),
Key: aws.String(eachRecord.SES.Mail.MessageID),
}
resp, err := svc.HeadObject(params)
logger.WithFields(logrus.Fields{
"Error": err,
"Metadata": resp,
}).Info("SES MessageBody")
}
}
}
示例5: transformImage
func transformImage(event *json.RawMessage, context *sparta.LambdaContext, w http.ResponseWriter, logger *logrus.Logger) {
logger.WithFields(logrus.Fields{
"RequestID": context.AWSRequestID,
"Event": string(*event),
}).Info("Request received :)")
var lambdaEvent spartaS3.Event
err := json.Unmarshal([]byte(*event), &lambdaEvent)
if err != nil {
logger.Error("Failed to unmarshal event data: ", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
}
logger.WithFields(logrus.Fields{
"S3Event": lambdaEvent,
}).Info("S3 Notification")
for _, eachRecord := range lambdaEvent.Records {
err = nil
// What happened?
switch eachRecord.EventName {
case "ObjectCreated:Put":
{
err = stampImage(eachRecord.S3.Bucket.Name, eachRecord.S3.Object.Key, logger)
}
case "s3:ObjectRemoved:Delete":
{
deleteKey := fmt.Sprintf("%s%s", transformPrefix, eachRecord.S3.Object.Key)
awsSession := awsSession(logger)
svc := s3.New(awsSession)
params := &s3.DeleteObjectInput{
Bucket: aws.String(eachRecord.S3.Bucket.Name),
Key: aws.String(deleteKey),
}
resp, err := svc.DeleteObject(params)
logger.WithFields(logrus.Fields{
"Response": resp,
"Error": err,
}).Info("Deleted object")
}
default:
{
logger.Info("Unsupported event: ", eachRecord.EventName)
}
}
//
if err != nil {
logger.Error("Failed to process event: ", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}
示例6: Describe
// Describe is not available in the AWS Lambda binary
func Describe(serviceName string,
serviceDescription string,
lambdaAWSInfos []*LambdaAWSInfo,
api *API,
site *S3Site,
s3BucketName string,
buildTags string,
linkerFlags string,
outputWriter io.Writer,
workflowHooks *WorkflowHooks,
logger *logrus.Logger) error {
logger.Error("Describe() not supported in AWS Lambda binary")
return errors.New("Describe not supported for this binary")
}
示例7: Provision
// Provision is not available in the AWS Lambda binary
func Provision(noop bool,
serviceName string,
serviceDescription string,
lambdaAWSInfos []*LambdaAWSInfo,
api *API,
site *S3Site,
s3Bucket string,
buildID string,
codePipelineTrigger string,
buildTags string,
linkerFlags string,
writer io.Writer,
workflowHooks *WorkflowHooks,
logger *logrus.Logger) error {
logger.Error("Deploy() not supported in AWS Lambda binary")
return errors.New("Deploy not supported for this binary")
}
示例8: echoKinesisEvent
////////////////////////////////////////////////////////////////////////////////
// Kinesis handler
//
func echoKinesisEvent(event *json.RawMessage, context *sparta.LambdaContext, w http.ResponseWriter, logger *logrus.Logger) {
logger.WithFields(logrus.Fields{
"RequestID": context.AWSRequestID,
"Event": string(*event),
}).Info("Request received")
var lambdaEvent spartaKinesis.Event
err := json.Unmarshal([]byte(*event), &lambdaEvent)
if err != nil {
logger.Error("Failed to unmarshal event data: ", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
}
for _, eachRecord := range lambdaEvent.Records {
logger.WithFields(logrus.Fields{
"EventID": eachRecord.EventID,
}).Info("Kinesis Event")
}
}
示例9: UploadTemplate
// UploadTemplate marshals the given cfTemplate and uploads it to the
// supplied bucket using the given KeyName
func UploadTemplate(serviceName string,
cfTemplate *gocf.Template,
s3Bucket string,
s3KeyName string,
awsSession *session.Session,
logger *logrus.Logger) (string, error) {
logger.WithFields(logrus.Fields{
"Key": s3KeyName,
"Bucket": s3Bucket,
}).Info("Uploading CloudFormation template")
s3Uploader := s3manager.NewUploader(awsSession)
// Serialize the template and upload it
cfTemplateJSON, err := json.Marshal(cfTemplate)
if err != nil {
logger.Error("Failed to Marshal CloudFormation template: ", err.Error())
return "", err
}
// Upload the actual CloudFormation template to S3 to maximize the template
// size limit
// Ref: http://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_CreateStack.html
contentBody := string(cfTemplateJSON)
uploadInput := &s3manager.UploadInput{
Bucket: &s3Bucket,
Key: &s3KeyName,
ContentType: aws.String("application/json"),
Body: strings.NewReader(contentBody),
}
templateUploadResult, templateUploadResultErr := s3Uploader.Upload(uploadInput)
if nil != templateUploadResultErr {
return "", templateUploadResultErr
}
// Be transparent
logger.WithFields(logrus.Fields{
"URL": templateUploadResult.Location,
}).Info("Template uploaded")
return templateUploadResult.Location, nil
}
示例10: echoAPIGatewayHTTPEvent
func echoAPIGatewayHTTPEvent(event *json.RawMessage,
context *LambdaContext,
w http.ResponseWriter,
logger *logrus.Logger) {
var lambdaEvent APIGatewayLambdaJSONEvent
err := json.Unmarshal([]byte(*event), &lambdaEvent)
if err != nil {
logger.Error("Failed to unmarshal event data: ", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
responseBody, err := json.Marshal(lambdaEvent)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
fmt.Fprint(w, string(responseBody))
}
}
示例11: echoDynamoDBEvent
////////////////////////////////////////////////////////////////////////////////
// DynamoDB handler
//
func echoDynamoDBEvent(event *json.RawMessage, context *sparta.LambdaContext, w http.ResponseWriter, logger *logrus.Logger) {
logger.WithFields(logrus.Fields{
"RequestID": context.AWSRequestID,
"Event": string(*event),
}).Info("Request received")
var lambdaEvent spartaDynamoDB.Event
err := json.Unmarshal([]byte(*event), &lambdaEvent)
if err != nil {
logger.Error("Failed to unmarshal event data: ", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
}
for _, eachRecord := range lambdaEvent.Records {
logger.WithFields(logrus.Fields{
"Keys": eachRecord.DynamoDB.Keys,
"NewImage": eachRecord.DynamoDB.NewImage,
}).Info("DynamoDb Event")
}
fmt.Fprintf(w, "Done!")
}
示例12: OnFile
func OnFile(e dispatcher.Event, p dispatcher.Path, log *logrus.Logger) {
u, err := New(e, p)
if err != nil {
log.Error(err)
return
}
if exists, total := u.FileCount(); exists != total {
log.WithFields(logrus.Fields{"path": u.Event.Dir()}).Infof("%d/%d files", exists, total)
return
}
// Verify
if err := u.Verify(); err != nil {
log.WithError(err).Warn("Verification failed")
return
}
log.WithFields(logrus.Fields{"path": u.Event.Dir()}).Info("Verified successfully")
// Unpack
if err := u.Run(); err != nil {
log.WithError(err).Error("Unpacking failed")
return
}
log.WithFields(logrus.Fields{"path": u.Event.Dir()}).Info("Unpacked successfully")
// Clean up
if ok, err := u.Remove(); err != nil {
log.WithError(err).Error("Failed to delete files")
} else if ok {
log.WithFields(logrus.Fields{"path": u.Event.Dir()}).Info("Cleaned up")
}
// Run post-command
if cmd, err := u.PostRun(); err != nil {
log.WithFields(logrus.Fields{"command": cmd}).WithError(err).Warn("Failed to run post-command")
} else if cmd != "" {
log.WithFields(logrus.Fields{"command": cmd}).Info("Executed post-command")
}
}
示例13: toReceiptAction
func (action *SESLambdaEventSourceResourceAction) toReceiptAction(logger *logrus.Logger) *ses.ReceiptAction {
actionProperties := action.ActionProperties
switch action.ActionType.Literal {
case "LambdaAction":
action := &ses.ReceiptAction{
LambdaAction: &ses.LambdaAction{
FunctionArn: aws.String(actionProperties["FunctionArn"].(string)),
InvocationType: aws.String("Event"),
},
}
if val, exists := actionProperties["InvocationType"]; exists {
action.LambdaAction.InvocationType = aws.String(val.(string))
}
if val, exists := actionProperties["TopicArn"]; exists {
action.LambdaAction.TopicArn = aws.String(val.(string))
}
return action
case "S3Action":
action := &ses.ReceiptAction{
S3Action: &ses.S3Action{
BucketName: aws.String(actionProperties["BucketName"].(string)),
},
}
if val, exists := actionProperties["KmsKeyArn"]; exists {
action.S3Action.KmsKeyArn = aws.String(val.(string))
}
if val, exists := actionProperties["ObjectKeyPrefix"]; exists {
action.S3Action.ObjectKeyPrefix = aws.String(val.(string))
}
if val, exists := actionProperties["TopicArn"]; exists {
action.S3Action.TopicArn = aws.String(val.(string))
}
return action
default:
logger.Error("No SESLmabdaEventSourceResourceAction marshaler found for action: " + action.ActionType.Literal)
}
return nil
}
示例14: Execute
// Execute creates an HTTP listener to dispatch execution. Typically
// called via Main() via command line arguments.
func Execute(lambdaAWSInfos []*LambdaAWSInfo, port int, parentProcessPID int, logger *logrus.Logger) error {
if port <= 0 {
port = defaultHTTPPort
}
server := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: NewLambdaHTTPHandler(lambdaAWSInfos, logger),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
if 0 != parentProcessPID {
logger.Debug("Sending SIGUSR2 to parent process: ", parentProcessPID)
syscall.Kill(parentProcessPID, syscall.SIGUSR2)
}
logger.Debug("Binding to port: ", port)
err := server.ListenAndServe()
if err != nil {
logger.Error("FAILURE: " + err.Error())
return err
}
logger.Debug("Server available at: ", port)
return nil
}
示例15: s3ItemInfo
func s3ItemInfo(event *json.RawMessage, context *sparta.LambdaContext, w http.ResponseWriter, logger *logrus.Logger) {
logger.WithFields(logrus.Fields{
"RequestID": context.AWSRequestID,
"Event": string(*event),
}).Info("Request received")
var lambdaEvent sparta.APIGatewayLambdaJSONEvent
err := json.Unmarshal([]byte(*event), &lambdaEvent)
if err != nil {
logger.Error("Failed to unmarshal event data: ", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
getObjectInput := &s3.GetObjectInput{
Bucket: aws.String(lambdaEvent.QueryParams["bucketName"]),
Key: aws.String(lambdaEvent.QueryParams["keyName"]),
}
awsSession := awsSession(logger)
svc := s3.New(awsSession)
result, err := svc.GetObject(getObjectInput)
if nil != err {
logger.Error("Failed to process event: ", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
presignedReq, _ := svc.GetObjectRequest(getObjectInput)
url, err := presignedReq.Presign(5 * time.Minute)
if nil != err {
logger.Error("Failed to process event: ", err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
httpResponse := map[string]interface{}{
"S3": result,
"URL": url,
}
responseBody, err := json.Marshal(httpResponse)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
w.Header().Set("Content-Type", "application/json")
fmt.Fprint(w, string(responseBody))
}
}