logger

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: Apache-2.0 Imports: 11 Imported by: 1

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

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 Critical

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

Critical, record CRITICAL message.

func Debug

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

Debug, record DEBUG message.

func Error

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

Error, record ERROR message.

func Info

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

Info, record INFO message.

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 Warning

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

Warning, record WARNING message.

Types

type LogLevel

type LogLevel int

type Logger

type Logger struct {
	Level         LogLevel
	Record        *Record
	Format        *Message
	StreamHandler *StreamMessageHandler
	SyncInterval  int
}

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 (*Logger) Critical

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

Critical, record CRITICAL message.

func (*Logger) Debug

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

Debug, record DEBUG message.

func (*Logger) Error

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

Error, record ERROR message.

func (*Logger) Info

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

Info, record INFO message.

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) Warning

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

Warning, record WARNING message.

type Message

type Message struct {
	FormatType    string
	ContentFormat string
	TimeFormat    string
}

Message log message struct

func (*Message) GetMessage

func (formatter *Message) GetMessage(record *Record) string

GetMessage, return formatted message string for output.

type Record

type Record struct {
	Level       LogLevel `json:"-"`
	LevelString string   `json:"level"`
	Message     string   `json:"message"`
	Pid         int      `json:"-"`
	Program     string   `json:"program"`
	Time        string   `json:"time"`
	FuncName    string   `json:"func_name"`
	Path        string   `json:"path"`
	FileName    string   `json:"file_name"`
	Line        int      `json:"line"`
	Color       string   `json:"-"`
	ColorClear  string   `json:"-"`
}

Record

func GetMessageRecord

func GetMessageRecord(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
	LogBuffer   *bytes.Buffer
}

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