log

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: MIT Imports: 10 Imported by: 0

README

go-logs

Build Status Github License Go Doc Go Report Card GoDoc reference example GitHub go.mod Go version of a Go module Github Latest Release Github Latest Tag Github Stars

⚙️ Installation

Download rabbitmq package by using:

go get github.com/ysk229/go-logs

🚀 Quick Start

Default options
    l := log.DefaultLogger
    l.Info("info") // 不打印
    l.Warnw("key", "value")
    l.Errorf("%v", "sdfdsfds")
    l.SetLevel("info")
    lg.Println("test")
    l.Info("show info log")
    l.SetLevel("warn")
    l.Warnw("key", "value")

Other usage examples

See the examples directory for more ideas.

Transient Dependencies

👏 Contributing

I love help! Contribute by forking the repo and opening pull requests. Please ensure that your code passes the existing tests and linting, and write tests to test your changes if applicable.

All pull requests should be submitted to the main branch.

Documentation

Index

Constants

View Source
const LevelKey = "level"

LevelKey is logger level key.

Variables

View Source
var (
	// DefaultCaller is a Valuer that returns the file and line.
	DefaultCaller = Caller(3)

	// DefaultTimestamp is a Valuer that returns the current wallclock time.
	DefaultTimestamp = Timestamp("2006-01-02.15:04:05.000000")
)

Functions

func NewJSONColorable

func NewJSONColorable() io.Writer

NewJSONColorable returns new instance of Writer which handles escape sequence from File.

func Value

func Value(ctx context.Context, v interface{}) interface{}

Value return the function value.

Types

type BaseLog

type BaseLog interface {
	Logger
	Info(a ...interface{})
	Warn(a ...interface{})
	Error(a ...interface{})
}

type Level

type Level int8

Level is a logger level.

const (
	// LevelDebug is logger debug level.
	LevelDebug Level = iota - 1
	// LevelInfo is logger info level.
	LevelInfo
	// LevelWarn is logger warn level.
	LevelWarn
	// LevelError is logger error level.
	LevelError
	// LevelFatal is logger fatal level
	LevelFatal
)

func ParseLevel

func ParseLevel(s string) Level

ParseLevel parses a level string into a logger Level value.

func (Level) String

func (l Level) String() string

type Log

type Log interface {
	BaseLog
	Debug(a ...interface{})
	Debugf(format string, a ...interface{})
	Debugw(keyvals ...interface{})

	Infof(format string, a ...interface{})
	Infow(keyvals ...interface{})

	Warnf(format string, a ...interface{})
	Warnw(keyvals ...interface{})

	Errorf(format string, a ...interface{})
	Errorw(keyvals ...interface{})

	Fatal(a ...interface{})
	Fatalf(format string, a ...interface{})
	Fatalw(keyvals ...interface{})
}

type Logger

type Logger interface {
	Log(level Level, keyvals ...interface{}) error
	SetLevel(level string)
}

Logger is a logger interface.

func With

func With(l Logger, kv ...interface{}) Logger

With with logger fields.

func WithContext

func WithContext(ctx context.Context, l Logger) Logger

WithContext returns a shallow copy of l with its context changed to ctx. The provided ctx must be non-nil.

type Valuer

type Valuer func(ctx context.Context) interface{}

Valuer is returns a log value.

func Caller

func Caller(depth int) Valuer

Caller returns a Valuer that returns a pkg/file:line description of the caller.

func Timestamp

func Timestamp(layout string) Valuer

Timestamp returns a timestamp Valuer with a custom time format.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer provides colorable Writer to the console

func (*Writer) Write

func (w *Writer) Write(data []byte) (n int, err error)

Write writes data on console

Directories

Path Synopsis
contrib
std
zap

Jump to

Keyboard shortcuts

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