package module
Version: v0.0.0-...-2f9db1a Latest Latest

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

Go to latest
Published: Nov 13, 2017 License: MIT Imports: 6 Imported by: 0


Cloudwatch hook for zap


package main

import (

func getLogger(name string) *zap.Logger {

	cred := credentials.NewStaticCredentials(awsAccessKey, awsSecretKey, "")
	cfg := aws.NewConfig().WithRegion(awsRegion).WithCredentials(cred)

	cloudwatchHook, err := zapcloudwatch.NewCloudwatchHook("xyz", "xyz1", false, cfg, zapcore.InfoLevel).GetHook()
	if err != nil {

	config := zap.NewDevelopmentConfig()
	config.Encoding = "json"
	logger, _ := config.Build()
	logger = logger.WithOptions(zap.Hooks(cloudwatchHook)).Named(name)
	return logger

func main() {
	logger, _ := getLogger("test")

	logger.Debug("don't need to send a message")
	logger.Error("an error happened!")


$ go get -u

This is a mixin project from these 2 repositories. Warning as a zaphook this hook doesn't log fields. If you need complete logging with fields don't use this hook. You need to implement zap.Core


Bahadir Bozdag




This section is empty.


AllLevels Supported log levels


func LevelThreshold

func LevelThreshold(l zapcore.Level) []zapcore.Level

LevelThreshold - Returns every logging level above and including the given parameter.


type CloudwatchHook

type CloudwatchHook struct {
	// Messages with a log level not contained in this array
	// will not be dispatched. If nil, all messages will be dispatched.
	AcceptedLevels []zapcore.Level
	GroupName      string
	StreamName     string
	AWSConfig      *aws.Config

	Async bool // if async is true, send a message asynchronously.
	// contains filtered or unexported fields

CloudwatchHook is a zap Hook for dispatching messages to the specified

func NewCloudwatchHook

func NewCloudwatchHook(groupName, streamName string, isAsync bool, cfg *aws.Config, level zapcore.Level) *CloudwatchHook

NewCloudwatchHook creates a new zap hook for cloudwatch

func (*CloudwatchHook) GetHook

func (ch *CloudwatchHook) GetHook() (func(zapcore.Entry) error, error)

GetHook function returns hook to zap

func (*CloudwatchHook) Levels

func (ch *CloudwatchHook) Levels() []zapcore.Level

Levels sets which levels to sent to cloudwatch

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL