lwlogger

package
v2.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

Lacework Logger

A wrapper Logger Go package for Lacework projects based of zap.

Usage

Download the library into your $GOPATH:

$ go get github.com/lacework/go-sdk/v2/lwlogger

Import the library into your tool:

import "github.com/lacework/go-sdk/v2/lwlogger"

Environment Variables

This package can be controlled via environment variables:

Environment Variable Description Default Supported Options
LW_LOG Change the verbosity of the logs "" INFO or DEBUG
LW_LOG_FORMAT Controls the format of the logs JSON JSON or CONSOLE
LW_LOG_DEV Switch the logger instance to development mode (extra verbose) false true or false

Examples

To create a new logger instance with the log level INFO, write an interesting info message and another debug message. Note that only the info message will be displayed:

package main

import "github.com/lacework/go-sdk/v2/lwlogger"

func main() {
	lwL := lwlogger.New("INFO")

	lwL.Debug("this is a debug message, too long and only needed when debugging this app")
	// This message wont be displayed

	lwL.Info("interesting info")
	// Output: {"level":"info","ts":"[timestamp]","caller":"main.go:9","msg":"interesting info"}
}

Look at the examples/ folder for more examples.

Documentation

Overview

A wrapper Logger package for Lacework projects based of zap logger.

Index

Constants

This section is empty.

Variables

View Source
var (
	// LogLevelEnv represents the level that the logger is configured
	LogLevelEnv        = "LW_LOG"
	SupportedLogLevels = [4]string{"", "ERROR", "INFO", "DEBUG"}

	// LogFormatEnv controls the format of the logger
	LogFormatEnv        = "LW_LOG_FORMAT"
	DefaultLogFormat    = "JSON"
	SupportedLogFormats = [2]string{"JSON", "CONSOLE"}

	// LogDevelopmentModeEnv switches the logger to development mode
	LogDevelopmentModeEnv = "LW_LOG_DEV"

	// LogToNativeLoggerEnv is used for those consumers like terraform that control
	// the logs that are presented to the user, when this environment is turned
	// on, the logger implementation will use the native Go logger 'log.Writer()'
	LogToNativeLoggerEnv = "LW_LOG_NATIVE"
)

Functions

func LogLevelFromEnvironment

func LogLevelFromEnvironment() string

LogLevelFromEnvironment checks the environment variable 'LW_LOG'

func Merge

func Merge(loggers ...*zap.Logger) *zap.Logger

Merges multiple loggers into one. A call to the merged logger will be forwarded to all the loggers

func New

func New(level string, options ...zap.Option) *zap.Logger

New initialize a new logger with the provided level and options

func NewWithFormat

func NewWithFormat(level string, format string, options ...zap.Option) *zap.Logger

func NewWithWriter

func NewWithWriter(level string, out io.Writer, options ...zap.Option) *zap.Logger

NewWithWriter initialize a new logger with the provided level and options but redirecting the logs to the provider io.Writer

func ValidLevel

func ValidLevel(level string) bool

Types

This section is empty.

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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