# README
log
对 zap 做了一个简单的封装,它支持从上下文获取 logger
并可以在 goroutine
中使用。
Description
包括 Debug
Debugf
Info
Infof
Warn
Warnf
Error
Errorf
Fatal
Fatalf
Panic
Panicf
和 With
Named
Sync
StdLogger
等函数.
描述 | |
---|---|
G | 返回一个 继承了 zap.Logger 的全局日志 |
ReplaceG | 通过参数将全局日志 G 替换 |
C | 直接从 context.Context 获取到 Logger . 如果上下文中没有包含一个 logger , 将会返回 G() . |
AssociateC | 返回 Logger 关联的 context.Context 的副本。 |
使用
package main
import (
"context"
"github.com/baishan-development-guizhou/golang-library/log"
"sync"
)
func main() {
var wg sync.WaitGroup
wg.Add(1)
logger := log.Configure().WithOutputEncoder(log.ConsoleOutputEncoder).WithCallerEncoder(log.ShortRoutineCallerEncoder).
WithStacktrace(false).WithLevel(log.DebugLevel).
Init()
logger = logger.With("dsd", "sdd")
ctx, _ := log.AssociateC(context.Background(), logger)
go func() {
iLogger := log.C(ctx)
iLogger.Info("second")
wg.Done()
}()
wg.Wait()
}
# Packages
No description provided by the author
# Functions
AssociateC returns a copy of context.Context in which the Logger associated.
C returns Logger from context.Context func.You should pass the Context,So that we can get the Logger from the context.
No description provided by the author
Debug logs a message at DebugLevel.
Debugf uses fmt.Sprintf to log a templated message.
Error logs a message at ErrorLevel.
Errorf uses fmt.Sprintf to log a templated message.
Fatal logs a message at FatalLevel.
Fatalf uses fmt.Sprintf to log a templated message.
G returns _global Logger extends from zap.Logger.
Info logs a message at InfoLevel.
Infof uses fmt.Sprintf to log a templated message.
Named adds a sub-scope to the logger's name.
Panic logs a message at PanicLevel.
Panicf uses fmt.Sprintf to log a templated message.
ReplaceG replace the _global logger with the one passed by the parameter.
Sync flushing any buffered log entries.Applications should take care to call Sync before exiting.
Warn logs a message at WarnLevel.
Warnf uses fmt.Sprintf to log a templated message.
With adds a variadic number of fields to the logging context.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
ZapLoggerAdapter adapter for Logger.
# Interfaces
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author