xlog

package module
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 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 Any

func Any(key string, val interface{}) zap.Field

func Bool

func Bool(key string, val bool) zap.Field

func ByteString

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

func Complex128

func Complex128(key string, val complex128) zap.Field

func Complex64

func Complex64(key string, val complex64) zap.Field

func DPanic

func DPanic(fields ...interface{})

func DPanicM added in v0.0.15

func DPanicM(msg string, m M)

func DPanicf added in v0.0.8

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

func Debug

func Debug(fields ...interface{})

func DebugM added in v0.0.15

func DebugM(msg string, m M)

func Debugf added in v0.0.8

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

func Duration

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

func Error

func Error(fields ...interface{})

func ErrorM added in v0.0.15

func ErrorM(msg string, m M)

func Errorf added in v0.0.8

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

func Fatal

func Fatal(fields ...interface{})

func FatalM added in v0.0.15

func FatalM(msg string, m M)

func Fatalf added in v0.0.8

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

func Float32

func Float32(key string, val float32) zap.Field

func Float64

func Float64(key string, val float64) zap.Field

func Info

func Info(fields ...interface{})

func InfoM added in v0.0.15

func InfoM(msg string, m M)

func Infof added in v0.0.8

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

func Int

func Int(key string, val int) zap.Field

func Int16

func Int16(key string, val int16) zap.Field

func Int32

func Int32(key string, val int32) zap.Field

func Int64

func Int64(key string, val int64) zap.Field

func Int8

func Int8(key string, val int8) zap.Field

func Named

func Named(s string, opts ...zap.Option) xlog_abc.Xlog

func New added in v0.0.6

func New(zl *zap.Logger) xlog_abc.Xlog

func Object

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

func Panic

func Panic(fields ...interface{})

func PanicM added in v0.0.15

func PanicM(msg string, m M)

func Panicf added in v0.0.8

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

func Reflect

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

func SetDefault added in v0.0.8

func SetDefault(lg xlog_abc.Xlog) (err error)

func Skip

func Skip() zap.Field

func Stack

func Stack(key string) zap.Field

func String

func String(key string, val string) zap.Field

func Stringer

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

func Sync

func Sync() error

func Time

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

func Uint

func Uint(key string, val uint) zap.Field

func Uint16

func Uint16(key string, val uint16) zap.Field

func Uint32

func Uint32(key string, val uint32) zap.Field

func Uint64

func Uint64(key string, val uint64) zap.Field

func Uint8

func Uint8(key string, val uint8) zap.Field

func Warn

func Warn(fields ...interface{})

func WarnM added in v0.0.15

func WarnM(msg string, m M)

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_abc.Xlog))

func With

func With(fields ...zap.Field) xlog_abc.Xlog

Types

type M added in v0.0.15

type M = xlog_abc.M

type Xlog added in v0.0.15

type Xlog = xlog_abc.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