xlog

package module
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 7 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 ...zap.Field)

func DPanicFn added in v0.0.13

func DPanicFn(msg string, fn func(fields *xlog_abc.Fields))

func DPanicf added in v0.0.8

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

func Debug

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

func DebugFn added in v0.0.13

func DebugFn(msg string, fn func(fields *xlog_abc.Fields))

func Debugf added in v0.0.8

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

func Error

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

func ErrorFn added in v0.0.13

func ErrorFn(msg string, fn func(fields *xlog_abc.Fields))

func Errorf added in v0.0.8

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

func Fatal

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

func FatalFn added in v0.0.13

func FatalFn(msg string, fn func(fields *xlog_abc.Fields))

func Fatalf added in v0.0.8

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

func Info

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

func InfoFn added in v0.0.13

func InfoFn(msg string, fn func(fields *xlog_abc.Fields))

func Infof added in v0.0.8

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

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 Panic

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

func PanicFn added in v0.0.13

func PanicFn(msg string, fn func(fields *xlog_abc.Fields))

func Panicf added in v0.0.8

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

func SetDefault added in v0.0.8

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

func Sync

func Sync() error

func Warn

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

func WarnFn added in v0.0.13

func WarnFn(msg string, fn func(fields *xlog_abc.Fields))

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

This section is empty.

Directories

Path Synopsis
internal
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