proto

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

View Source
const (
	LevelDebug = Level(0)
	LevelInfo  = Level(1)
	LevelWarn  = Level(2)
	LevelError = Level(3)
	LevelFatal = Level(4)
)

Variables

This section is empty.

Functions

func FailLog

func FailLog(err error)

TODO: output the failed log to syslog

func Marshal

func Marshal(l *Proto) ([]byte, error)

func ToMsg

func ToMsg(i ...interface{}) []byte

func ToMsgf

func ToMsgf(f string, i ...interface{}) []byte

Types

type Adapter

type Adapter interface {
	Put(log *Proto)
	Close()
}

type Context

type Context struct {
	Platform string `json:"platform"`
	Version  string `json:"version"`
	Ip       string `json:"ip"`
}

func (Context) String

func (c Context) String() string

type Data

type Data struct {
	Date   time.Time `json:"date"`
	Level  Level     `json:"level"`
	Logger string    `json:"logger"`
	Msg    []byte    `json:"msg"`
}

func (Data) String

func (d Data) String() string

type Level

type Level int

func (Level) ColorString

func (l Level) ColorString() string

func (Level) Int

func (l Level) Int() int

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	SetOutputLevel(level Level)
	GetOutputLevel() Level

	SetAdapter(adapter []Adapter)
	GetAdapter() []Adapter

	Debug(msg ...interface{})
	Debugf(f string, msg ...interface{})

	Info(msg ...interface{})
	Infof(f string, msg ...interface{})

	Warn(msg ...interface{})
	Warnf(f string, msg ...interface{})

	Error(msg ...interface{})
	Errorf(f string, msg ...interface{})

	Fatal(msg ...interface{})
	Fatalf(f string, msg ...interface{})

	Exit(code int, msg ...interface{}) // exit with info level message
	ExitWithLevel(code int, level Level, msg ...interface{})

	// When exit program, need to call Close function to fush the log output.
	Close()

	// Compatibility interfaces
	// Same as Info level
	Print(msg ...interface{})
	Printf(f string, msg ...interface{})

	// Compatibility interfaces
	// Same as Fatal level
	Panic(msg ...interface{})
	Panicf(f string, msg ...interface{})
}

type Proto

type Proto struct {
	Context *Context `json:"context"`
	Data    []*Data  `json:"data"`
}

func Unmarshal

func Unmarshal(src []byte) (*Proto, error)

Jump to

Keyboard shortcuts

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