zapz

package module
v0.0.0-...-3f0c596 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

Zapz: Uber's Zap --> logzio

Zapz creates a zap.Logger that sends logs to logzio. This creates a custom WriterSync that buffers data on disk and drains every 5 seconds.

Zapz uses logzio-go to transport logs via HTTP

GoDoc Build Status Coverage Status Go Report

Installation

$ go get -u github.com/dougEfresh/zapz

Quick Start

package main

import (
 "os"

 "github.com/dougEfresh/zapz"
   )

func main() {
 l, err := zapz.New(os.Args[1]) //logzio token required
 if err != nil {
   panic(err)
 }

 l.Info("tester")
 // Logs are buffered on disk, this will flush it
 if l.Sync() != nil {
     panic("oops")
 }
}

Getting Started

Get Logzio token
  1. Go to Logzio website
  2. Sign in with your Logzio account
  3. Click the top menu gear icon (Account)
  4. The Logzio token is given in the account page

Usage

Set Debug level: zapz.New(token, zapz.SetLevel(zapcore.DebugLevel))

Set CustomEncoder config: zapz.New(token, zapz.SetEncodeConfig(cfg))

Set Custom log type:

A type field is created by default: zap.String("type", "zap-logger"). You can change it like so zapz.New(token, zapz.SetType(logzType))

Examples

passwd-pot

lambdazap

Prerequisites

go 1.x

Tests

$ go test -v

Contributing

All PRs are welcome

Authors

License

This project is licensed under the Apache License - see the LICENSE file for details

Acknowledgments

logz java

TODO

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = zapcore.EncoderConfig{
	TimeKey:        "ts",
	LevelKey:       "level",
	NameKey:        "logger",
	CallerKey:      "caller",
	MessageKey:     "message",
	StacktraceKey:  "stacktrace",
	LineEnding:     zapcore.DefaultLineEnding,
	EncodeLevel:    zapcore.LowercaseLevelEncoder,
	EncodeTime:     LogzTimeEncoder,
	EncodeDuration: zapcore.SecondsDurationEncoder,
	EncodeCaller:   zapcore.ShortCallerEncoder,
}

DefaultConfig - Message needs to be the message key for logzio

Functions

func LogzTimeEncoder

func LogzTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

LogzTimeEncoder format to time.RFC3339Nano

func New

func New(token string, opts ...Option) (*zap.Logger, error)

New will create a zap logger compatible with logz

func NewLogz

func NewLogz(logz *logzio.LogzioSender, opts ...Option) (*zap.Logger, error)

NewLogz will create a zap logger compatible with logz

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

An Option configures a Logger.

func SetEncodeConfig

func SetEncodeConfig(c zapcore.EncoderConfig) Option

SetEncodeConfig set the encoder

func SetLevel

func SetLevel(l zapcore.Level) Option

SetLevel set the log level

func SetLogz

func SetLogz(c *logzio.LogzioSender) Option

SetLogz use this logzsender

func SetType

func SetType(ty string) Option

SetType setting log type zap.Field

func WithDebug

func WithDebug(w io.Writer) Option

WithDebug enables debugging output for log

type Zapz

type Zapz struct {
	// contains filtered or unexported fields
}

Zapz struct for logging

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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