naivelog

package module
v0.0.0-...-03c508b Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: Unlicense Imports: 9 Imported by: 0

README

NaiveLog

A pracitce of cuslog

Documentation

Overview

to define the log entry struct

to define the Formatter interface for formatting based on different format

to implement a text formatter fundemental text output format

the logger is to construct logs

Index

Constants

View Source
const (
	FmtEmptySeparate = ""
)

Variables

View Source
var LevelNameMap = map[Level]string{
	Debug: "DEBUG",
	Info:  "INFO",
	Warn:  "WARN",
	Error: "ERROR",
	Panic: "PANIC",
	Fatal: "FATAL",
}

Functions

func New

func New(opts ...Option) *logger

func SetOptions

func SetOptions(opts ...Option)

for the standard logger, the same belows

func StdLogger

func StdLogger() *logger

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 // the file which prints this entry
	Line   int    // the code line where this entry is printed
	Func   string // the function which prints this entry
	Format string // the format of argument delimiter
	Args   []interface{}
	// contains filtered or unexported fields
}

type Formatter

type Formatter interface {
	Format(entry *Entry) error
}

type Level

type Level uint8 // log level
const (
	Debug Level = iota
	Info
	Warn
	Error
	Panic
	Fatal
)

type Option

type Option func(*options)

func WithDisableCaller

func WithDisableCaller(caller bool) Option

func WithFormatter

func WithFormatter(formatter Formatter) Option

func WithLevel

func WithLevel(level Level) Option

func WithStdLevel

func WithStdLevel(level Level) Option

type TextFormatter

type TextFormatter struct {
	// to determine if the basic info should be printed
	IgnoreBasicFields bool
}

func (*TextFormatter) Format

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

Jump to

Keyboard shortcuts

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