xlog

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2021 License: MIT Imports: 9 Imported by: 40

README

xlog

xlog is a simple and easy-to-use logger with zap logger as the bottom abstraction

介绍

xlog是一个对zap logger的简单的封装, 意在简化配置, 增强可控, 简洁易用。

example

package example_test

import (
	"testing"
	"time"

	"github.com/pubgo/dix"
	"github.com/pubgo/xerror"
	"github.com/pubgo/xlog"
	"github.com/pubgo/xlog/internal"
	"github.com/pubgo/xlog/xlog_config"
)

var log = xlog.GetLog()

func init() {
	dix.Go(func(log1 xlog.XLog) {
		log = log1.
			Named("service").With(xlog.String("key", "service")).
			Named("hello").With(xlog.String("key", "hello")).
			Named("world").With(xlog.String("key", "world"))
	})
}

func TestExample(t *testing.T) {
	log.Debug("hello",
		xlog.Any("hss", "ss"),
	)

	dix.Go(initCfgFromJsonDebug(time.Now().Format("2006-01-02 15:04:05")))

	log.Info("hello",
		xlog.Any("hss", "ss"),
	)
	//fmt.Println(dix.Graph())
}

func initCfgFromJsonDebug(name string) internal.XLog {
	cfg := `{
        "level": "debug",
        "development": true,
        "disableCaller": false,
        "disableStacktrace": false,
        "sampling": null,
        "encoding": "console",
        "encoderConfig": {
                "messageKey": "M",
                "levelKey": "L",
                "timeKey": "T",
                "nameKey": "N",
                "callerKey": "C",
                "stacktraceKey": "S",
                "lineEnding": "\n",
                "levelEncoder": "capitalColor",
                "timeEncoder": "iso8601",
                "durationEncoder": "string",
                "callerEncoder": "default",
                "nameEncoder": ""
        },
        "outputPaths": [
                "stderr"
        ],
        "errorOutputPaths": [
                "stderr"
        ],
        "initialFields": null
}`

	zl, err := xlog_config.NewZapLoggerFromJson([]byte(cfg), xlog_config.WithEncoding("console"))
	xerror.Exit(err)
	return xlog.New(zl.WithOptions(xlog.AddCallerSkip(1)))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DPanic

func DPanic(msg string, fields ...Field)

func DPanicf added in v0.0.8

func DPanicf(format string, a ...interface{})

func Debug

func Debug(msg string, fields ...Field)

func Debugf added in v0.0.8

func Debugf(format string, a ...interface{})

func Error

func Error(msg string, fields ...Field)

func Errorf added in v0.0.8

func Errorf(format string, a ...interface{})

func Fatal

func Fatal(msg string, fields ...Field)

func Fatalf added in v0.0.8

func Fatalf(format string, a ...interface{})

func GetDefault added in v0.0.11

func GetDefault() *log.XLog

func Info

func Info(msg string, fields ...Field)

func Infof added in v0.0.8

func Infof(format string, a ...interface{})

func Panic

func Panic(msg string, fields ...Field)

func Panicf added in v0.0.8

func Panicf(format string, a ...interface{})

func SetDefault added in v0.0.8

func SetDefault(zl XLog) (err error)

func Sync

func Sync(ll ...XLog) (err error)

func Warn

func Warn(msg string, fields ...Field)

func Warnf added in v0.0.8

func Warnf(format string, a ...interface{})

func Watch added in v0.0.11

func Watch(fn func(logs XLog))

Types

type Field

type Field = zap.Field

func Any

func Any(key string, value interface{}) Field

func Binary

func Binary(key string, val []byte) Field

func Bool

func Bool(key string, val bool) Field

func ByteString

func ByteString(key string, val []byte) Field

func Complex128

func Complex128(key string, val complex128) Field

func Complex64

func Complex64(key string, val complex64) Field

func Duration

func Duration(key string, val time.Duration) Field

func Float32

func Float32(key string, val float32) Field

func Float64

func Float64(key string, val float64) Field

func Fmt

func Fmt(format string, a ...interface{}) Field

func Int

func Int(key string, val int) Field

func Int16

func Int16(key string, val int16) Field

func Int32

func Int32(key string, val int32) Field

func Int64

func Int64(key string, val int64) Field

func Int8

func Int8(key string, val int8) Field

func Object

func Object(key string, val zapcore.ObjectMarshaler) Field

func Reflect

func Reflect(key string, val interface{}) Field

func Skip

func Skip() Field

func Stack

func Stack(key string) Field

func String

func String(key string, val string) Field

func Stringer

func Stringer(key string, val fmt.Stringer) Field

func Time

func Time(key string, val time.Time) Field

func Uint

func Uint(key string, val uint) Field

func Uint16

func Uint16(key string, val uint16) Field

func Uint32

func Uint32(key string, val uint32) Field

func Uint64

func Uint64(key string, val uint64) Field

func Uint8

func Uint8(key string, val uint8) Field

type Fields added in v0.0.6

type Fields []Field

func (*Fields) Skip added in v0.0.11

func (t *Fields) Skip() *Fields

type Option added in v0.0.6

type Option = zap.Option

func WithCaller added in v0.0.6

func WithCaller(enabled bool) Option

func WithCallerSkip added in v0.0.11

func WithCallerSkip(skip int) Option

func WithDevelopment added in v0.0.11

func WithDevelopment() Option

func WithErrorOutput added in v0.0.11

func WithErrorOutput(w zapcore.WriteSyncer) Option

func WithFields added in v0.0.11

func WithFields(fs ...Field) Option

func WithHooks added in v0.0.11

func WithHooks(hooks ...func(zapcore.Entry) error) Option

func WithIncreaseLevel added in v0.0.11

func WithIncreaseLevel(lvl zapcore.LevelEnabler) Option

func WithOnFatal added in v0.0.11

func WithOnFatal(action zapcore.CheckWriteAction) Option

func WithStacktrace added in v0.0.11

func WithStacktrace(lvl zapcore.LevelEnabler) Option

type XLog

type XLog = internal.XLog

func GetDevLog

func GetDevLog() XLog

func Named

func Named(s string, opts ...zap.Option) XLog

func New added in v0.0.6

func New(zl *zap.Logger) XLog

func With

func With(fields ...zap.Field) XLog

Directories

Path Synopsis
log
writer/rotate/file-rotatelogs
package rotatelogs is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify.
package rotatelogs is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify.

Jump to

Keyboard shortcuts

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