xlog

package module
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: MIT Imports: 8 Imported by: 7 modules, 40 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

xlog

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

example

package main

import (
	"encoding/json"

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

var log xlog.Xlog

func init() {
	xlog.Watch(func(logs xlog.Xlog) {
		log = logs.Named("test")
	})
}

func main() {
	log.Info("hello", xlog.String("ss", "hello1"))
	xlog.Info("hello", xlog.String("ss", "hello1"))
	xlog.Infof("hello %s", "1234")
	xlog.InfoM("hello %s", xlog.M{
		"test": "ok",
	})
	xlog.Warn("test")

	initCfgFromJson()

	xlog.Info("hello", xlog.String("ss", "hello1"))
	xlog.Infof("hello %s", "1234")
	xlog.InfoM("hello %s", xlog.M{
		"test": "ok",
	})
	xlog.Warn("test")
	log.Info("hello", xlog.String("ss", "hello1"))
	xlog.WarnW(func(log xlog.Logger) {
		log.Println("hello w")
	})
	log.WarnW(func(log xlog.Logger) {
		log.Print("hhhh jnjnjnj")
	})
}

func initCfgFromJson() {
	cfg := `{
        "level": "info",
        "development": false,
        "disableCaller": false,
        "disableStacktrace": false,
        "sampling": {
                "initial": 100,
                "thereafter": 100
        },
        "encoding": "json",
        "encoderConfig": {
                "messageKey": "msg",
                "levelKey": "level",
                "timeKey": "ts",
                "nameKey": "logger",
                "callerKey": "caller",
                "stacktraceKey": "stacktrace",
                "lineEnding": "\n",
                "levelEncoder": "default",
                "timeEncoder": "default",
                "durationEncoder": "default",
                "callerEncoder": "full",
                "nameEncoder": "default"
        },
        "outputPaths": ["stderr"],
        "errorOutputPaths": ["stderr"],
        "initialFields": null
}`

	var cfg1 xlog_config.Config
	xerror.Exit(json.Unmarshal([]byte(cfg), &cfg1))
	cfg1.Encoding = "console"
	zl, err := cfg1.Build()

	xerror.Exit(err)
	xerror.Exit(xlog.SetDefault(xlog.New(zl)))
	xlog.Warn("test")
}

日志切割

https://github.com/natefinch/lumberjack

日志分析

https://github.com/allinurl/goaccess

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DPanic

func DPanic(args ...interface{})

func DPanicW added in v0.0.22

func DPanicW(fn func(log Logger))

func DPanicf added in v0.0.8

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

func Debug

func Debug(args ...interface{})

func DebugW added in v0.0.22

func DebugW(fn func(log Logger))

func Debugf added in v0.0.8

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

func ErrWith added in v0.2.8

func ErrWith(name string, err error)

func Error

func Error(args ...interface{})

func ErrorW added in v0.0.22

func ErrorW(fn func(log Logger))

func Errorf added in v0.0.8

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

func Fatal

func Fatal(args ...interface{})

func FatalW added in v0.0.22

func FatalW(fn func(log Logger))

func Fatalf added in v0.0.8

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

func Info

func Info(args ...interface{})

func InfoW added in v0.0.22

func InfoW(fn func(log Logger))

func Infof added in v0.0.8

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

func Panic

func Panic(args ...interface{})

func PanicW added in v0.0.22

func PanicW(fn func(log Logger))

func Panicf added in v0.0.8

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

func SetDefault added in v0.0.8

func SetDefault(logger *zap.Logger) (err error)

SetDefault 设置默认的zap logger

func Warn

func Warn(args ...interface{})

func WarnW added in v0.0.22

func WarnW(fn func(log Logger))

func Warnf added in v0.0.8

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

Types

type Logger added in v0.1.0

type Logger interface {
	Printf(format string, v ...interface{})
	Print(v ...interface{})
	Println(v ...interface{})
	PrintM(m M)
}

type M added in v0.0.15

type M map[string]interface{}

type Xlog added in v0.0.15

type Xlog interface {
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	DPanic(args ...interface{})
	Panic(args ...interface{})
	Fatal(args ...interface{})

	DebugW(func(log Logger))
	InfoW(func(log Logger))
	WarnW(func(log Logger))
	ErrorW(func(log Logger))
	DPanicW(func(log Logger))
	PanicW(func(log Logger))
	FatalW(func(log Logger))

	Debugf(format string, a ...interface{})
	Infof(format string, a ...interface{})
	Warnf(format string, a ...interface{})
	Errorf(format string, a ...interface{})
	Panicf(format string, a ...interface{})
	Fatalf(format string, a ...interface{})
	DPanicf(format string, a ...interface{})

	Named(name string, opts ...zap.Option) Xlog
}

func GetDefault added in v0.0.11

func GetDefault() Xlog

GetDefault 获取默认xlog

func GetLogger added in v0.1.4

func GetLogger(name string, opts ...zap.Option) Xlog

Directories

Path Synopsis
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
⌂ 换网址