zapparser

package module
v0.0.0-...-cf1af15 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

README

Documentation

zap-parser

A golang parser for Uber's zap logger json output.

Quick Start

import (
    // ...
    "fmt"

	"github.com/Yacast/zap-parser"
)

p, err := zapparser.FromFile("/path/to/logs"))
if err != nil {
	panic(err)
}

p.OnError(func(err error) {
    fmt.Println(err)
})

p.OnEntry(func(e *zapparser.Entry) {
    fmt.Println(e.Message)
})

p.Start()
fmt.Println("Done parsing...")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Caller    string
	Extras    map[string]interface{}
	Level     zapcore.Level
	Message   string
	Timestamp time.Time
}

Entry is a log entry

type Parser

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

Parser holds the zap logs parser

func FromBytes

func FromBytes(bs []byte) *Parser

FromFile creates a new scanner from a byte slice.

func FromFile

func FromFile(path string) (*Parser, error)

FromFile creates a new scanner from a file path.

func FromString

func FromString(s string) *Parser

FromString creates a new scanner from a string.

func NewParser

func NewParser(r io.Reader) *Parser

NewParser creates a new parser

func (*Parser) OnClose

func (p *Parser) OnClose(callback func()) error

OnClose adds a callback on parser close

func (*Parser) OnEntry

func (p *Parser) OnEntry(callback func(*Entry)) error

OnEntry adds a callback on entry found

func (*Parser) OnError

func (p *Parser) OnError(callback func(error)) error

OnError adds a callback on parsing line error

func (*Parser) Start

func (p *Parser) Start()

Start will starts parsing logs. Start is blocking and will return when parsing is done or an error occured

func (*Parser) Stop

func (p *Parser) Stop()

Stop stops parsing

Jump to

Keyboard shortcuts

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