zlog

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: MIT Imports: 10 Imported by: 0

README

zlog

MIT codecov Go Reference Go Report Card

a simple async log library of go

Example

first go get

go get github.com/AtlanCI/zlog

Write file

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/AtlanCI/zlog"
	"github.com/AtlanCI/zlog/helper"
)

func main() {
	l, err := helper.NewTextFileLogger("./test.log")
	if err != nil {
		_, _ = fmt.Fprintln(os.Stderr, "NewTextFileLogger: ", err)
		return
	}

	zlog.AddLoggers(l)

	// Enabled on Caller will reduce performance by 15%
	zlog.SetCallerEnable(true)

	defer zlog.Close()

	zlog.Debugf(context.TODO(), "this is a debug log. a=%d", 888)
}

Stdout

package main

import (
	"context"

	"github.com/AtlanCI/zlog"
	"github.com/AtlanCI/zlog/helper"
)

func main() {

	// stdout 
	l := helper.NewTextStdoutLogger()
	
	zlog.AddLoggers(l)

	// Enabled on Caller will reduce performance by 15%
	zlog.SetCallerEnable(true)

	defer zlog.Close()

	zlog.Debugf(context.TODO(), "this is a debug log. a=%d", 888)
}

Feat

  • scroll file

  • trace id

  • Asynchronous

todo

  • stained

  • compression

  • more test

  • delete old file

  • document

  • godoc and awesome go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLoggers

func AddLoggers(l ...Logger)

func AddStainingUsers

func AddStainingUsers(tags ...string)

func Close

func Close()

func Debugf

func Debugf(ctx context.Context, format string, v ...interface{})

func DelStainingUsers

func DelStainingUsers(tags ...string)

func Errorf

func Errorf(ctx context.Context, format string, v ...interface{})

func GetStainingUsers

func GetStainingUsers() []string

func HijackStdlog

func HijackStdlog()

HijackStdlog hijack standard log Hijack standard library log.Print not fmt.Println... example: [2022-11-26 19:08:24][1669460913.111][D] [stdlog]the is example log

func Infof

func Infof(ctx context.Context, format string, v ...interface{})

func LevelEnabled

func LevelEnabled(lv Level) bool

func Logf

func Logf(ctx context.Context, caller *Caller, lv Level, format string, v ...interface{})

func SetCallerEnable

func SetCallerEnable(enable bool)

func Warnf

func Warnf(ctx context.Context, format string, v ...interface{})

func WrapWriter

func WrapWriter(lv Level, tag string) io.Writer

Types

type Caller

type Caller struct {
	Line int
	File string
}

type Level

type Level int8

Level is a logger Level

const (
	// LevelError is logger error level
	LevelError Level = iota
	// LevelWarn is logger warn level
	LevelWarn
	// LevelInfo is logger info level
	LevelInfo
	// LevelDebug is logger debug level
	LevelDebug
)

func (Level) Enabled

func (l Level) Enabled(lv Level) bool

Enabled compare whether th logging level is enabled.

func (Level) String

func (l Level) String() string

func (Level) StringShort

func (l Level) StringShort() byte

type Logger

type Logger interface {
	// Log need to format and output: Time Level TraceID Caller Message(format,v...)
	//! Do not filter level, just log.
	Log(t time.Time, lv Level, tid string, c *Caller, format string, v ...interface{})

	// SetLevel set logger level
	SetLevel(Level)

	// GetLevel use by log to filter
	GetLevel() Level

	// Close file or other output resource
	Close()
}

Logger is a log record

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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