zlog

package
v0.0.0-...-cfec3e1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initial

func Initial(options ...zap.Option)

Initial 创建日志实例并替换 zap.L 全局调用

Example
package main

import (
	"go.uber.org/zap"

	"github.com/frank-yf/go-tool/internal/pkg/zlog"
)

func main() {
	zlog.Initial()

	zap.L().Debug("this an debug message") // cannot output
	zap.L().Info("this an info message")

	zap.S().Debug("this an debug message for sugar") // cannot output
	zap.S().Info("this an info message for sugar")

	_ = zap.L().Sync()
}
Output:

�[34mINFO�[0m	this an info message
�[34mINFO�[0m	this an info message for sugar

func New

func New(options ...zap.Option) (*zap.Logger, error)

New 创建日志实例

func UseDebug

func UseDebug()
Example
package main

import (
	"go.uber.org/zap"

	"github.com/frank-yf/go-tool/internal/pkg/zlog"
)

func main() {
	zlog.UseDebug()
	zlog.Initial()

	zap.L().Debug("debug message")
	zap.L().Info("info message")

	zap.S().Debug("debug message for sugar")
	zap.S().Info("info message for sugar")

	_ = zap.L().Sync()
}
Output:

�[35mDEBUG�[0m	zlog/log_test.go:28	github.com/frank-yf/go-tool/internal/pkg/zlog_test.ExampleUseDebug	debug message
�[34mINFO�[0m	zlog/log_test.go:29	github.com/frank-yf/go-tool/internal/pkg/zlog_test.ExampleUseDebug	info message
�[35mDEBUG�[0m	zlog/log_test.go:31	github.com/frank-yf/go-tool/internal/pkg/zlog_test.ExampleUseDebug	debug message for sugar
�[34mINFO�[0m	zlog/log_test.go:32	github.com/frank-yf/go-tool/internal/pkg/zlog_test.ExampleUseDebug	info message for sugar

Types

This section is empty.

Jump to

Keyboard shortcuts

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