cuslog

package module
v0.0.0-...-80a9233 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

After calling the log print function, you also need to print these logs to the supported output, so you need to implement the write function, whose write logic is stored in the `entry.go` file.

Index

Constants

View Source
const (
	FmtEmptySeparate = ""
)

Variables

View Source
var LevelNameMapping = map[Level]string{
	DebugLevel: "DEBUG",
	InfoLevel:  "INFO",
	WarnLevel:  "WARN",
	ErrorLevel: "ERROR",
	PanicLevel: "PANIC",
	FatalLevel: "FATAL",
}

log level string name mapping

Functions

func Debug

func Debug(args ...interface{})

std logger

func Debugf

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

func Error

func Error(args ...interface{})

func Errorf

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

func Fatal

func Fatal(args ...interface{})

func Fatalf

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

func Info

func Info(args ...interface{})

func Infof

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

func New

func New(opts ...Option) *logger

func Panic

func Panic(args ...interface{})

func Panicf

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

func SetOptions

func SetOptions(opts ...Option)

func StdLogger

func StdLogger() *logger

func Warn

func Warn(args ...interface{})

func Warnf

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

func Writer

func Writer() io.Writer

Types

type Entry

type Entry struct {
	Buffer *bytes.Buffer
	Map    map[string]interface{}
	Level  Level
	Time   time.Time
	File   string
	Line   int
	Func   string
	Format string
	Args   []interface{}
	// contains filtered or unexported fields
}

Type is used to store all log information, that is, log configuration and log content. The writing logic is done around an instance of the Entry type.

type Formatter

type Formatter interface {
	// Maybe in async goroutine
	// Please write the result to buffer
	Format(entry *Entry) error
}

type JsonFormatter

type JsonFormatter struct {
	IgnoreBasicFields bool
}

func (*JsonFormatter) Format

func (f *JsonFormatter) Format(e *Entry) error

type Level

type Level uint8

log level

const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel Level = iota
	// InfoLevel is the default logging priority.
	InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
)

const log level

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(text []byte) error

UnmarshalText unmarshals text to a level.

type Option

type Option func(*options)

func WithDisableCaller

func WithDisableCaller(caller bool) Option

Sets whether to print the file name and line number.

func WithFormatter

func WithFormatter(formatter Formatter) Option

Set log formatter.

func WithLevel

func WithLevel(level Level) Option

Set log output level.

func WithOutput

func WithOutput(output io.Writer) Option

Set output location.

func WithStdLevel

func WithStdLevel(level Level) Option

Set log output level.

type TextFormatter

type TextFormatter struct {
	IgnoreBasicFields bool
}

func (*TextFormatter) Format

func (f *TextFormatter) Format(e *Entry) error

Directories

Path Synopsis
After the cuslog package is developed, you can write test code and call the cuslog package to test whether the functions of the cuslog package are normal.
After the cuslog package is developed, you can write test code and call the cuslog package to test whether the functions of the cuslog package are normal.

Jump to

Keyboard shortcuts

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