zap

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) *zap.Logger

New returns a zap logger.

func NewLogger

func NewLogger(opts ...Option) *kratoszap.Logger

NewLogger returns a wrapped zap logger of kratos.

Types

type Config

type Config = zap.Config

type Level

type Level = zapcore.Level
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel Level = iota - 1
	// InfoLevel is the default logging priority.
	InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
)

type Option

type Option func(config *Config)

func Verbose

func Verbose(flag bool) Option

Verbose alias WithLevel setter log level to DebugLevel

Example
package main

import (
	"github.com/omalloc/contrib/kratos/zap"
)

func main() {

	log := zap.New(zap.Verbose(true))
	log.Info("info")
	log.Debug("debug")
}
Output:

{"level":"info"}
{"level":"debug"}

func WithEncoding

func WithEncoding(encoding string) Option

WithEncoding setter log encoding. only support `json` and `console`

func WithLevel

func WithLevel(lvl Level) Option

WithLevel setter log level. alias zap.config.OutputPaths

Example
package main

import (
	"github.com/omalloc/contrib/kratos/zap"
)

func main() {

	log := zap.New(zap.WithLevel(zap.InfoLevel))
	log.Debug("no-debug")
	log.Info("info")
}
Output:

{"level":"info"}

func WithLevelString

func WithLevelString(lvl string) Option

WithLevelString setter log level (string-alias)

func WithOutput

func WithOutput(paths []string) Option

WithOutput setter log output paths. valid `stdout` `stderr`

Jump to

Keyboard shortcuts

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