zlog

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: MIT Imports: 4 Imported by: 4

README

logo

Build Status Coverage Status GoDoc Go Report Card license

zlog

Just Log Basic On zerolog

Install

$ go get -u github.com/haozibi/zlog

Demo

package main

import (
	"fmt"
	"os"

	"github.com/haozibi/zlog"
	"github.com/pkg/errors"
)

func init() {

	zlog.NewBasic(os.Stdout, zlog.WithColor(), zlog.WithDebug())
	// zlog.NewJSONLog(os.Stdout)
}

func main() {
	zlog.ZInfo().
		Int("z", 100-1).
		Msg("just do it")

	zlog.ZDebug().
		Float64("f", 3.1415926).
		Msgf("hello %s", "zlog")

	var err error

	err = doit()
	if err != nil {
		zlog.ZError().Stack().Err(err).Msg("[doit] some error")
	}

	err = doErr()
	if err != nil {
		zlog.ZError().Err(err).Msg("[do error]")
	}

}

func doit() error {
	err := doErr()
	if err != nil {
		return errors.Wrap(err, "just error")
	}
	return nil
}

func doErr() error {
	return fmt.Errorf("some error")
}

Documentation

Overview

Example
NewBasic(os.Stdout, WithDebug(), WithTimeFormat("2006"))
// zlog.NewJSONLog(os.Stdout)

ZInfo().
	Int("z", 100-1).
	Msg("just do it")

ZDebug().
	Float64("f", 3.1415926).
	Msgf("hello %s", "zlog")
Output:

2019 INF example_test.go:11 > just do it z=99
2019 DBG example_test.go:15 > hello zlog f=3.1415926

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// TimeFieldFormat time format
	TimeFieldFormat = time.RFC3339

	// TimeFormatUnixNano time format
	TimeFormatUnixNano = "2006-01-02 15:04:05.999999999"

	// NoColor if set color
	NoColor = false
)

Functions

func NewBasic added in v1.0.0

func NewBasic(w io.Writer, opts ...Option)

NewBasic new basic format log

func NewJSON added in v1.0.0

func NewJSON(w io.Writer, opts ...Option)

NewJSON new log by json format

func ZDebug

func ZDebug() *zerolog.Event

ZDebug debug log

func ZError

func ZError() *zerolog.Event

ZError error log

func ZFatal

func ZFatal() *zerolog.Event

ZFatal fatal log

func ZInfo

func ZInfo() *zerolog.Event

ZInfo info log

func ZWarn

func ZWarn() *zerolog.Event

ZWarn warn log

Types

type Level added in v1.0.1

type Level int8

Level defines log levels.

const (
	// DebugLevel defines debug log level.
	DebugLevel Level = iota
	// InfoLevel defines info log level.
	InfoLevel
	// WarnLevel defines warn log level.
	WarnLevel
	// ErrorLevel defines error log level.
	ErrorLevel
	// FatalLevel defines fatal log level.
	FatalLevel
	// NoLevel defines an absent log level.
	NoLevel
	// Disabled disables the logger.
	Disabled

	// TraceLevel defines trace log level.
	TraceLevel Level = -1
)

type Option added in v1.0.0

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

Option overrides behavior of zlog.

func WithColor added in v1.0.0

func WithColor() Option

WithColor enable log color

func WithDebug added in v0.1.3

func WithDebug() Option

WithDebug enable debug mode, show code line num

func WithDeep added in v0.1.3

func WithDeep(n int) Option

WithDeep set line deep,default eq 2

func WithLevel added in v1.0.1

func WithLevel(l Level) Option

WithLevel set log output level

func WithTimeFormat added in v0.1.3

func WithTimeFormat(format string) Option

WithTimeFormat set time format when basic format

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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