lambdalogger

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2020 License: AGPL-3.0 Imports: 6 Imported by: 0

README

lambdalogger

Initialize a zap logger for your Lambda function with the request ID and other initial fields.

This makes it possible to easily search for logs from a given invocation and is required for all Panther Go Lambda functions.

Example Usage

package main

import (
    "context"

    "github.com/aws/aws-lambda-go/lambda"
    "go.uber.org/zap"

    "github.com/panther-labs/panther/pkg/lambdalogger"
)

func lambdaHandler(ctx context.Context, event interface{}) {
    // Configure the global zap logger.
    // DEBUG mode is used if strings.lower(os.Getenv("DEBUG")) == "true".
    lambdaContext, logger := lambdalogger.ConfigureGlobal(ctx, nil)

    // The returned logger is the same as the global zap logger: zap.L()
    // The global zap logger can now be called from anywhere in the source code.
    logger.Info("function invoked", zap.Any("event", event))
    zap.L().Info("another way to log", zap.String("arn", lambdaContext.InvokedFunctionArn))
}

func main() {
    lambda.Start(lambdaHandler)
}

Documentation

Overview

Package lambdalogger updates the global zap logger for use in a Lambda function.

Index

Constants

View Source
const Application = "panther" // tag all logs with "application" -> "panther" (used for audit)

Variables

View Source
var DebugEnabled = strings.ToLower(os.Getenv("DEBUG")) == "true"

DebugEnabled is true if the DEBUG environment variable is set to true.

Functions

func ConfigureGlobal

func ConfigureGlobal(
	ctx context.Context,
	initialFields map[string]interface{},
) (*lambdacontext.LambdaContext, *zap.Logger)

ConfigureGlobal adds the Lambda request ID to the global zap logger.

To add fields to every log message, include them in initialFields (the requestID is added for you).

Returns parsed Lambda context, global zap logger.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL