logger

package module
v0.0.0-...-7ffd2bc Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2020 License: MIT Imports: 8 Imported by: 0

README

sdk-zap

基于 uber 开源的 zap 二次封装

使用例子

package logger_test

import (
    "testing"
    
    logger "github.com/golearnku/sdk-zap"
    "go.uber.org/zap"
)

func TestMain(t *testing.M) {
    logger.New(logger.SetEnv("dev"), logger.SetPath("./log"))
    t.Run()
}

func TestGetLogger(t *testing.T) {
    logger.Logger().Info("msg", zap.String("uid", "abc"))
    logger.Logger().Debug("debug", zap.String("uid", "abc"))
    logger.Logger().Error("error", zap.String("uid", "abc"))
    
    // 多实例日志
    logger.Logger("goim").Info("info", zap.String("uid", "abc"))
    logger.Logger("goim").Error("error", zap.String("uid", "abc"))
    logger.Logger("goim").Debug("debug", zap.String("uid", "abc"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(arg ...string) *zap.Logger

Logger 获取日志实例

func New

func New(opts ...Option) *logger

New 初始化日志实例

func NewLogger

func NewLogger(cfg zap.Config) (logger *zap.Logger, err error)

NewLogger New is similar to Config.Build except that info and error logs are separated only json/console encoder is supported (zap doesn't provide a way to refer to other encoders)

Types

type Option

type Option func(o *options)

Option 日志配置选项

func SetDebug

func SetDebug(debug bool) Option

SetDebug 设置日志是否开启调试模式

func SetEnv

func SetEnv(env string) Option

SetEnv 设置日志环境变量

func SetOutput

func SetOutput(output bool) Option

SetOutput 设置是否标准输出

func SetPath

func SetPath(path string) Option

SetPath 设置日志路径

Jump to

Keyboard shortcuts

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