zapparser

package module
v0.0.0-...-698a958 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 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

Times:

If your logs are in the timestamp format:

"2006-01-02T15:04:05.999Z"

Please use p.TimeIsNonUnix

If your times are in

1568146267.0402062

format, please change nothing

package main

import (
	"fmt"

	zapparser "github.com/seal/zap-parser"
)

func main() {
	p, err := zapparser.FromFile("./logs.log")
	p.TimeIsNonUnix = true
	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 {
	TimeIsNonUnix bool
	// 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