zapsetup

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: MIT Imports: 2 Imported by: 0

README

简介

本仓库旨在提供适用于一般场合的 zaplog 配置,做好"最后一公里".

繁介

zaplog 有着强大又灵活的配置项,但多数场合并不需要太多功能. 其自带的 Production 也仅适用在超高吞吐量的场合. 因此, 当你想关闭采样输出, 或者想在控制台查看日志, 又或者想要动态修改 log.Level, 还或者 想实现一些sink把日志投递到日志存储&分析系统里, 那就看看这个仓库里的代码吧.

Usage

import (
	zapsetup "github.com/upgrade-or-die/zap-setup"
)

var (
	log  = zapsetup.RootLogger()
	log2 = log.Sugar()
)

func main() {
	log.Info("hello zaplog")
	log2.Infof("hello %s", "小明")

	// change log level on the fly
	log.SetLevel(zap.DebugLevel)
	log.Debug("hello zaplog")
	log2.Infof("hello %s", "小明")
}

TODO

  • aliyun-sls-sink
  • aws-watchlog-sink

LICENCE

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CoreX added in v0.1.2

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

func NewCoreX added in v0.1.2

func NewCoreX(l *zap.Logger, sink Sink) *CoreX

func (*CoreX) Check added in v0.1.2

func (*CoreX) Enabled added in v0.1.2

func (c *CoreX) Enabled(level zapcore.Level) bool

func (*CoreX) Sync added in v0.1.2

func (c *CoreX) Sync() error

func (*CoreX) With added in v0.1.2

func (c *CoreX) With(fields []zapcore.Field) zapcore.Core

func (*CoreX) Write added in v0.1.2

func (c *CoreX) Write(ent zapcore.Entry, fields []zapcore.Field) error

type LoggerX

type LoggerX struct {
	*zap.Logger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(opts ...Option) *LoggerX

func RootLogger

func RootLogger() *LoggerX

func (*LoggerX) SetLevel

func (l *LoggerX) SetLevel(level zapcore.Level) *LoggerX

SetLevel atomically

func (*LoggerX) WithSink added in v0.1.2

func (l *LoggerX) WithSink(s Sink) *LoggerX

type Option

type Option func(*zap.Config)

func WithLogLevel

func WithLogLevel(level zapcore.Level) Option

func WithSampling

func WithSampling(c *zap.SamplingConfig) Option

type Sink added in v0.1.2

type Sink interface {
	Open()
	Close()
	Write(ent zapcore.Entry, fields []zapcore.Field)
}

Directories

Path Synopsis
sink

Jump to

Keyboard shortcuts

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