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

# Packages

No description provided by the author

# 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