package
1.10.3
Repository: https://github.com/caring/go-packages.git
Documentation: pkg.go.dev

# README

Tracing

About

This package contains tooling to configure and create fast, structured loggers. This package is a thin wrapper around Uber Zap.

Configuration

Most of the logging configuration can be done through environment variables. Any values passed into the logging initialization config object will overwrite environment variables. See the table below for details. AWS authorization, region and all other account info are pulled from the hardware that the logger is running on.

PropertyDescriptionDefault
SERVICE_NAMEThe service name"" Empty String
LOG_NAMEThe name of the logger"" Empty String
LOG_LEVELThe lowest logged level. All all levels above this will be logged to all enabled outputs"INFO"
LOG_ENABLE_DEVBoolean which enables the developer log configuration compatible with zap-pretty"FALSE"
LOG_STREAM_MONITORINGThe name of the kinesis stream where developer monitoring logs are piped through"" Empty String
LOG_STREAM_REPORTINGThe name of the kinesis stream where business insight lgs are piped through"" Empty String
LOG_DISABLE_KINESISBoolean flag to disable out put to kinesis, generally only enabled in Prod"TRUE"
LOG_FLUSH_INTERVALIf kinesis is enabled, this sets the number of seconds between buffer flushes for each underlying kinesis io stream"10"
LOG_BUFFER_SIZEIf kinesis is enabled, this sets the byte size of each of the kinesis io buffers"262144" (256 * 1024)
ENVThe current environment"" Empty String

Usage


t := true
f := false
config := &Config{
		LoggerName:          "my-logger",
		ServiceName:         "my-service",
		LogLevel:            "INFO",
		EnableDevLogging:    &f,
		KinesisStreamName:   "stream-1",
		KinesisPartitionKey: "shard-1",
		DisableKinesis:      &t,
  },
}

  logger, err := NewLogger(config)

  logger.Warn("sample message", logging.Int64("fieldA", 3))

  // To obtain a chain interceptor for you gRPC server...
  logger.NewGRPCUnaryServerInterceptor()
  // or
  logger.NewGRPCStreamServerInterceptor()

Pretty Printing

The development logger outputs logs in a format usable by this tool.

First brew install it

$ brew install maoueh/tap/zap-pretty

Then when you run your service pipe the output to the pretty-printer

$ ./main | zap-pretty

# Packages

No description provided by the author

# Functions

Any takes a key and an arbitrary value and chooses the best way to represent them as a field, falling back to a reflection-based approach only if necessary.
Bool constructs a field with a bool value.
Bools constructs a field with a slice of bools value.
Float64 constructs a field with a float64 value.
Float64s constructs a field with a slice of float64s value.
Int64 constructs a field with a int64 value.
Int64s constructs a field with a slice of int64s value.
NewLogger initializes a new logger and connects it to a kinesis stream if enabled.
NewNopLogger returns a new logger that wont log outputs, wont error, and wont call any internal hooks.
String constructs a field with a string value.
Strings constructs a field with a slice of strings value.

# Constants

DebugLevel logs are typically voluminous, and are usually disabled in production.
DPanicLevel logs are particularly important errors.
ErrorLevel logs are high-priority.
FatalLevel logs a message, then calls os.Exit(1).
InfoLevel is the default logging priority.
PanicLevel logs a message, then panics.
WarnLevel logs are more important than Info, but don't need individual human review.

# Structs

Config encapsulates the various settings that may be applied to a logger.
Field is a typed and structured log entry string key and value pair.
FieldOpts wraps internal field values that can be updated when spawning a child logger.
Logger provides fast, structured, type safe leveled logging.

# Type aliases

A Level is a logging priority.