本文整理匯總了Golang中github.com/Sirupsen/logrus.Logger.Info方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.Info方法的具體用法?Golang Logger.Info怎麽用?Golang Logger.Info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Sirupsen/logrus.Logger
的用法示例。
在下文中一共展示了Logger.Info方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Explore
// Explore supports interactive command line invocation of the previously
// provisioned Sparta service
func Explore(lambdaAWSInfos []*LambdaAWSInfo, port int, logger *logrus.Logger) error {
if 0 == port {
port = 9999
}
urlHost := fmt.Sprintf("http://localhost:%d", port)
logger.Info("The following URLs are available for testing.")
msgText := ""
// Get unique paths
lambdaPaths := make(map[string]*LambdaAWSInfo, 0)
for _, eachLambdaInfo := range lambdaAWSInfos {
lambdaPaths[eachLambdaInfo.lambdaFnName] = eachLambdaInfo
}
for _, eachLambdaInfo := range lambdaPaths {
functionURL := fmt.Sprintf("%s/%s", urlHost, eachLambdaInfo.lambdaFnName)
logger.WithFields(logrus.Fields{
"URL": functionURL,
}).Info(eachLambdaInfo.lambdaFnName)
if msgText == "" {
msgText = fmt.Sprintf("\tcurl -vs -X POST -H \"Content-Type: application/json\" --data @testEvent.json %s", functionURL)
}
}
logger.Info("Functions can be invoked via application/json over POST")
logger.Info(msgText)
logger.Info("Where @testEvent.json is a local file with top level `context` and `event` properties:")
logger.Info("\t{context: {}, event: {}}")
// Start up the localhost server and publish the info
return Execute(lambdaAWSInfos, port, 0, logger)
}
示例2: Delete
// Delete the provided serviceName. Failing to delete a non-existent
// service is not considered an error. Note that the delete does
func Delete(serviceName string, logger *logrus.Logger) error {
session := awsSession(logger)
awsCloudFormation := cloudformation.New(session)
exists, err := stackExists(serviceName, awsCloudFormation, logger)
if nil != err {
return err
}
logger.WithFields(logrus.Fields{
"Exists": exists,
"Name": serviceName,
}).Info("Stack existence check")
if exists {
params := &cloudformation.DeleteStackInput{
StackName: aws.String(serviceName),
}
resp, err := awsCloudFormation.DeleteStack(params)
if nil != resp {
logger.WithFields(logrus.Fields{
"Response": resp,
}).Info("Delete request submitted")
}
return err
}
logger.Info("Stack does not exist")
return nil
}
示例3: 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
}
示例4: create
func (command HelloWorldResource) create(session *session.Session,
logger *logrus.Logger) (map[string]interface{}, error) {
logger.Info("create: Hello ", command.Message)
return map[string]interface{}{
"Resource": "Created message: " + command.Message,
}, nil
}
示例5: s3LambdaProcessor
func s3LambdaProcessor(event *json.RawMessage, context *LambdaContext, w http.ResponseWriter, logger *logrus.Logger) {
logger.WithFields(logrus.Fields{
"RequestID": context.AWSRequestID,
}).Info("S3Event")
logger.Info("Event data: ", string(*event))
}
示例6: exploreTestHelloWorld
func exploreTestHelloWorld(event *json.RawMessage,
context *LambdaContext,
w http.ResponseWriter,
logger *logrus.Logger) {
logger.Info("Hello World: ", string(*event))
fmt.Fprint(w, string(*event))
}
示例7: echoS3SiteAPIGatewayEvent
// NOTE: your application MUST use `package main` and define a `main()` function. The
// example text is to make the documentation compatible with godoc.
func echoS3SiteAPIGatewayEvent(event *json.RawMessage,
context *LambdaContext,
w http.ResponseWriter,
logger *logrus.Logger) {
logger.Info("Hello World: ", string(*event))
fmt.Fprint(w, string(*event))
}
示例8: createNewNodeJSProxyEntry
// Return a string representation of a JS function call that can be exposed
// to AWS Lambda
func createNewNodeJSProxyEntry(lambdaInfo *LambdaAWSInfo, logger *logrus.Logger) string {
// Create an entry of the form:
logger.Info("Creating NodeJS proxy entry: " + lambdaInfo.jsHandlerName())
primaryEntry := fmt.Sprintf("exports[\"%s\"] = createForwarder(\"/%s\");\n",
lambdaInfo.jsHandlerName(),
lambdaInfo.lambdaFnName)
return primaryEntry
}
示例9: 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)
}
}
}
示例10: cloudWatchEventProcessor
func cloudWatchEventProcessor(event *json.RawMessage,
context *LambdaContext,
w http.ResponseWriter,
logger *logrus.Logger) {
logger.WithFields(logrus.Fields{
"RequestID": context.AWSRequestID,
}).Info("Request received")
logger.Info("CloudWatch Event data: ", string(*event))
}
示例11: ensureConfiguratorLambdaResource
func ensureConfiguratorLambdaResource(awsPrincipalName string, sourceArn string, resources ArbitraryJSONObject, S3Bucket string, S3Key string, logger *logrus.Logger) (string, error) {
// AWS service basename
awsServiceName := awsPrincipalToService(awsPrincipalName)
configuratorExportName := strings.ToLower(awsServiceName)
//////////////////////////////////////////////////////////////////////////////
// IAM Role definition
// TODO - Check sourceArn for equivalence
iamResourceName, err := ensureIAMRoleResource(awsPrincipalName, sourceArn, resources, logger)
if nil != err {
return "", err
}
iamRoleRef := ArbitraryJSONObject{
"Fn::GetAtt": []string{iamResourceName, "Arn"},
}
// Custom handler resource for this service type
subscriberHandlerName := fmt.Sprintf("%sSubscriber", awsServiceName)
_, exists := resources[subscriberHandlerName]
if !exists {
logger.Info("Creating Subscription Lambda Resource for AWS service: ", awsServiceName)
//////////////////////////////////////////////////////////////////////////////
// Custom Resource Lambda Handler
// NOTE: This brittle function name has an analog in ./resources/index.js b/c the
// AWS Lamba execution treats the entire ZIP file as a module. So all module exports
// need to be forwarded through the module's index.js file.
handlerName := fmt.Sprintf("index.%sConfiguration", configuratorExportName)
logger.Debug("Lambda Configuration handler: ", handlerName)
customResourceHandlerDef := ArbitraryJSONObject{
"Type": "AWS::Lambda::Function",
"Properties": ArbitraryJSONObject{
"Code": ArbitraryJSONObject{
"S3Bucket": S3Bucket,
"S3Key": S3Key,
},
"Role": iamRoleRef,
"Handler": handlerName,
"Runtime": "nodejs",
"Timeout": "30",
},
}
resources[subscriberHandlerName] = customResourceHandlerDef
}
return subscriberHandlerName, nil
}
示例12: archiveHook
func archiveHook(context map[string]interface{},
serviceName string,
zipWriter *zip.Writer,
awsSession *session.Session,
noop bool,
logger *logrus.Logger) error {
logger.Info("Adding userResource")
resourceFileName := "userResource.json"
binaryWriter, binaryWriterErr := zipWriter.Create(resourceFileName)
if nil != binaryWriterErr {
return binaryWriterErr
}
userdataReader := strings.NewReader(userdataResourceContents)
_, copyErr := io.Copy(binaryWriter, userdataReader)
return copyErr
}
示例13: WaitForStackOperationComplete
// WaitForStackOperationComplete is a blocking, polling based call that
// periodically fetches the stackID set of events and uses the state value
// to determine if an operation is complete
func WaitForStackOperationComplete(stackID string,
pollingMessage string,
awsCloudFormation *cloudformation.CloudFormation,
logger *logrus.Logger) (*WaitForStackOperationCompleteResult, error) {
result := &WaitForStackOperationCompleteResult{}
// Poll for the current stackID state, and
describeStacksInput := &cloudformation.DescribeStacksInput{
StackName: aws.String(stackID),
}
for waitComplete := false; !waitComplete; {
sleepDuration := time.Duration(11+rand.Int31n(13)) * time.Second
time.Sleep(sleepDuration)
describeStacksOutput, err := awsCloudFormation.DescribeStacks(describeStacksInput)
if nil != err {
// TODO - add retry iff we're RateExceeded due to collective access
return nil, err
}
if len(describeStacksOutput.Stacks) <= 0 {
return nil, fmt.Errorf("Failed to enumerate stack info: %v", *describeStacksInput.StackName)
}
result.stackInfo = describeStacksOutput.Stacks[0]
switch *(result.stackInfo).StackStatus {
case cloudformation.StackStatusCreateComplete,
cloudformation.StackStatusUpdateComplete:
result.operationSuccessful = true
waitComplete = true
case
// Include DeleteComplete as new provisions will automatically rollback
cloudformation.StackStatusDeleteComplete,
cloudformation.StackStatusCreateFailed,
cloudformation.StackStatusDeleteFailed,
cloudformation.StackStatusRollbackFailed,
cloudformation.StackStatusRollbackComplete,
cloudformation.StackStatusUpdateRollbackComplete:
result.operationSuccessful = false
waitComplete = true
default:
logger.Info(pollingMessage)
}
}
return result, nil
}
示例14: stackExists
// Does a given stack exist?
func stackExists(stackNameOrID string, cf *cloudformation.CloudFormation, logger *logrus.Logger) (bool, error) {
describeStacksInput := &cloudformation.DescribeStacksInput{
StackName: aws.String(stackNameOrID),
}
describeStacksOutput, err := cf.DescribeStacks(describeStacksInput)
logger.Debug("DescribeStackOutput: ", describeStacksOutput)
exists := false
if err != nil {
logger.Info("DescribeStackOutputError: ", err)
// If the stack doesn't exist, then no worries
if strings.Contains(err.Error(), "does not exist") {
exists = false
} else {
return false, err
}
} else {
exists = true
}
return exists, nil
}
示例15: Explore
// Explore supports interactive command line invocation of the previously
// provisioned Sparta service
func Explore(serviceName string, logger *logrus.Logger) error {
session := awsSession(logger)
awsCloudFormation := cloudformation.New(session)
exists, err := stackExists(serviceName, awsCloudFormation, logger)
if nil != err {
return err
} else if !exists {
logger.Info("Stack does not exist: ", serviceName)
return nil
} else {
resources, err := stackLambdaResources(serviceName, awsCloudFormation, logger)
if nil != err {
return nil
}
selected := promptForSelection(resources)
if nil != selected {
logger.Info("TODO: Invoke", selected)
}
}
return nil
}