logger

package
Version: v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorRed     // red
	ColorGreen   // green
	ColorYellow  // yellow
	ColorBlue    // blue
	ColorMagenta // magenta

	ColorWhite // white
)
View Source
const (
	TextType = "text"
	JsonType = "json"
)

LogType

View Source
const (
	NOTSET   = iota
	DEBUG    = LogLevel(10 * iota) // DEBUG = 10
	INFO     = LogLevel(10 * iota) // INFO = 20
	NOTICE   = LogLevel(10 * iota) // INFO = 30
	WARNING  = LogLevel(10 * iota) // WARNING = 40
	ERROR    = LogLevel(10 * iota) // ERROR = 50
	CRITICAL = LogLevel(10 * iota) // CRITICAL = 60
)

MessageLevel

View Source
const LevelColorSetClear = "\033[0m"
View Source
const MaxWarnLogFileCount = 20
View Source
const TraceName = "X-OR-TRACE-ID"

Variables

View Source
var LevelColorFlag = []string{
	DEBUG:    colorSet(ColorWhite, 0),
	INFO:     colorSet(ColorGreen, 0),
	NOTICE:   colorSet(ColorBlue, 0),
	WARNING:  colorSet(ColorYellow, 0),
	ERROR:    colorSet(ColorRed, 1),
	CRITICAL: colorSet(ColorMagenta, 1),
}

LevelColorFlag, MessageLevel color flag.

View Source
var LevelString = map[LogLevel]string{
	DEBUG:    "DEBUG",
	INFO:     "INFO",
	NOTICE:   "NOTICE",
	WARNING:  "WARNING",
	ERROR:    "ERROR",
	CRITICAL: "CRITICAL",
}

Functions

func CloseProducer added in v0.5.1

func CloseProducer()

func Critical

func Critical(format string, a ...interface{})

Critical, record CRITICAL message.

func Criticalw added in v0.2.8

func Criticalw(message string, kv ...interface{})

Criticalw, record CRITICAL message with kv format.

func Debug

func Debug(format string, a ...interface{})

Debug, record DEBUG message.

func Debugw added in v0.2.8

func Debugw(message string, kv ...interface{})

Debugw, record DEBUG message with kv format.

func Error

func Error(format string, a ...interface{})

Error, record ERROR message.

func Errorw added in v0.2.8

func Errorw(message string, kv ...interface{})

Errorw, record ERROR message with kv format.

func Info

func Info(format string, a ...interface{})

Info, record INFO message.

func Infow added in v0.2.8

func Infow(message string, kv ...interface{})

Infow, record INFO message with kv format.

func LogCloseAll added in v0.2.8

func LogCloseAll()

func LogIsStart

func LogIsStart() bool

LogIsStart, check is open.

func NewLogger

func NewLogger()

初始化logger快速方法

func Notice

func Notice(format string, a ...interface{})

Notice, record INFO message.

func Noticew added in v0.2.8

func Noticew(message string, kv ...interface{})

Noticew, record INFO message with kv format.

func Warning

func Warning(format string, a ...interface{})

Warning, record WARNING message.

func Warningw added in v0.2.8

func Warningw(message string, kv ...interface{})

Warningw, record WARNING message with kv format.

Types

type Field added in v0.2.8

type Field struct {
	Key   string
	Type  reflect.Type
	Value interface{}
}

func Any added in v0.2.8

func Any(key string, value interface{}) Field

func Reflect added in v0.2.8

func Reflect(key string, valType reflect.Type, val interface{}) Field

type LogLevel

type LogLevel int

type Logger

type Logger struct {
	Level         LogLevel
	Record        *Record
	Format        *Message
	StreamHandler *StreamMessageHandler
	SyncInterval  int
	// contains filtered or unexported fields
}

Logger main logger struct

func LogFile

func LogFile(fileName string) *Logger

LogFile, new log file save.

func New

func New(level LogLevel, logType string, logDir string, syncInterval int) *Logger

New get logger struct

func WithContext added in v0.5.2

func WithContext(c context.Context) *Logger

WithContext, 注入上下文.

func (*Logger) Critical

func (l *Logger) Critical(format string, a ...interface{})

Critical, record CRITICAL message.

func (*Logger) Criticalw added in v0.2.8

func (l *Logger) Criticalw(message string, kv ...interface{})

Criticalw, record CRITICAL message with kv format.

func (*Logger) Debug

func (l *Logger) Debug(format string, a ...interface{})

Debug, record DEBUG message.

func (*Logger) Debugw added in v0.2.8

func (l *Logger) Debugw(message string, kv ...interface{})

Debugw, record DEBUG message with kv format

func (*Logger) Error

func (l *Logger) Error(format string, a ...interface{})

Error, record ERROR message.

func (*Logger) Errorw added in v0.2.8

func (l *Logger) Errorw(message string, kv ...interface{})

Errorw, record ERROR message with kv format.

func (*Logger) Info

func (l *Logger) Info(format string, a ...interface{})

Info, record INFO message.

func (*Logger) Infow added in v0.2.8

func (l *Logger) Infow(message string, kv ...interface{})

Infow, record INFO message with kv format.

func (*Logger) LogDeferClose added in v0.2.8

func (l *Logger) LogDeferClose()

LogDeferClose close handler

func (*Logger) LogFile

func (l *Logger) LogFile(fileName string) *Logger

LogFile, change default log file name.

func (*Logger) Notice

func (l *Logger) Notice(format string, a ...interface{})

Notice, record INFO message.

func (*Logger) Noticew added in v0.2.8

func (l *Logger) Noticew(message string, kv ...interface{})

Noticew, record INFO message with kv format.

func (*Logger) Warning

func (l *Logger) Warning(format string, a ...interface{})

Warning, record WARNING message.

func (*Logger) Warningw added in v0.2.8

func (l *Logger) Warningw(message string, kv ...interface{})

Warningw, record WARNING message with kv format.

type Message

type Message struct {
	FormatType    string
	ContentFormat string
	TimeFormat    string
}

Message log message struct

func (*Message) GetFieldKvJson added in v0.2.8

func (formatter *Message) GetFieldKvJson(fields []Field) (kvJson string)

GetFieldKvJson

func (*Message) GetMessage

func (formatter *Message) GetMessage(record *Record) []byte

GetMessage, return formatted message string for output.

func (*Message) GetRecordKvJsonByte added in v0.2.8

func (formatter *Message) GetRecordKvJsonByte(record *Record, fields []Field) (jsonByte []byte)

GetKvJson

type Record

type Record struct {
	Level       LogLevel `json:"-"`
	LevelString string   `json:"level"`
	LogFile     string   `json:"log_file"`
	Message     string   `json:"message"`
	TraceId     string   `json:"or_trace_id,omitempty"`
	KvField     []Field  `json:"-"`
	KvJson      string   `json:"-"`
	Pid         int      `json:"-"`
	Program     string   `json:"program"`
	Time        string   `json:"time"`
	FuncName    string   `json:"func_name"`
	Path        string   `json:"path"`
	FileName    string   `json:"file"`
	Line        int      `json:"line"`
	Color       string   `json:"-"`
	ColorClear  string   `json:"-"`
}

Record

func GetMessageKVRecord added in v0.2.8

func GetMessageKVRecord(c context.Context, level LogLevel, message string, kv ...interface{}) *Record

GetMessageKVRecord, make a record and return it's reference.

func GetMessageRecord

func GetMessageRecord(c context.Context, level LogLevel, format string, a ...interface{}) *Record

GetMessageRecord, make a record and return it's reference.

type StreamMessageHandler

type StreamMessageHandler struct {
	LogDir         string
	LogFileName    string
	LogExt         string
	LogFilePath    string
	LogBuffer      *bytes.Buffer
	BufferLine     uint64
	LogFileHandler *os.File
	// contains filtered or unexported fields
}

StreamMessageHandler

func (*StreamMessageHandler) SyncLog

func (handler *StreamMessageHandler) SyncLog()

SyncLog interval sync log stream buffer

func (*StreamMessageHandler) Write

func (handler *StreamMessageHandler) Write(message []byte)

Write write log to buffer

Jump to

Keyboard shortcuts

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