elog

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: MIT Imports: 11 Imported by: 1

README

elog high perfermance logger lib for golang

global logger model

func main() {
	flag.Parse()
	defer elog.Flush()
	for i := 0; i < 100; i++ {
		go func() {
			elog.Info("hello", "world")
		}()
	}
	time.Sleep(time.Second)
}

./example_elog -logToStderr -logLevel=INFO -logFlushTime=3 -logPath=./

LoggerHandler model

type TestLogHandler struct {
}

func (lh *TestLogHandler) Write(data []byte) (int, error) {

	return os.Stderr.Write(data)
}

func (lh *TestLogHandler) Flush() {
	os.Stderr.Write([]byte("flush\n"))
}

func main() {
	writer := &TestLogHandler{}
	log := elog.NewEasyLogger("INFO", false, 3, writer)
	defer log.Flush()
	log.Info("hello", "world")
}

elog config

-logFlushTime int
    	log flush time interval,default 3 seconds (default 3)
  -logLevel string
    	log level[DEBUG,INFO,WARN,ERROR,NONE],default INFO level (default "INFO")
  -logPath string
    	log path,default log to current directory (default "./")
  -logToStderr
    	log to stderr,default false

elog rotate file rules

1.when file size reach to 1GB,the logger file will be rotate
2.rotate files max num is 10

elog high performance

log to cache buffer then flush to file
cache buffer size is 1M
default flush time 3 seconds,-logFlushTime can change flush time interval
if want close log outputing,-logLevel=NONE can close log outputing

Documentation

Index

Constants

View Source
const (
	LOG_LEVEL_DEBUG         = 1
	LOG_LEVEL_INFO          = 2
	LOG_LEVEL_WARN          = 3
	LOG_LEVEL_ERROR         = 4
	LOG_LEVEL_FATAL         = 5
	LOG_LEVEL_NONE          = 6
	LOG_MAX_FILE_SIZE       = 1024 * 1024 * 1024
	LOG_MAX_BUFFER_SIZE     = 1024 * 1024
	LOG_MAX_ROTATE_FILE_NUM = 10
	LOG_DEPTH_GLOBAL        = 4
	LOG_DEPTH_HANDLER       = 3
)
View Source
const (
	WITH_FILE_LINE    = 0
	WITH_NO_FILE_LINE = 1
)

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

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 Flush

func Flush()

func GetFlushTime

func GetFlushTime() int

func GetLogHistory

func GetLogHistory() int

func GetLogLevel

func GetLogLevel() string

func GetLogPath

func GetLogPath() string

func GetMode

func GetMode() int

func Info

func Info(args ...interface{})

func Infof

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

func Printf

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

func Println

func Println(args ...interface{})

func SetLogLevel

func SetLogLevel(level string)

func SetLogPath

func SetLogPath(logPath string)

func SetLogToStderr

func SetLogToStderr(mode bool)

func SetMode

func SetMode(mode int)

func Warn

func Warn(args ...interface{})

func Warningf

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

Types

type EasyFileHandler

type EasyFileHandler struct {
	// contains filtered or unexported fields
}

func NewEasyFileHandler

func NewEasyFileHandler(path string, bufferSize int) *EasyFileHandler

func (*EasyFileHandler) Flush

func (efh *EasyFileHandler) Flush()

func (*EasyFileHandler) Write

func (efh *EasyFileHandler) Write(data []byte) (int, error)

type EasyLogHandler

type EasyLogHandler interface {
	io.Writer
	Flush()
}

type EasyLogger

type EasyLogger struct {
	// contains filtered or unexported fields
}

func GetLogger

func GetLogger() *EasyLogger

func NewEasyLogger

func NewEasyLogger(logLevel string, logToStderr bool, flushTime int, writer EasyLogHandler) *EasyLogger

func (*EasyLogger) Debug

func (el *EasyLogger) Debug(args ...interface{})

func (*EasyLogger) Debugf

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

func (*EasyLogger) Error

func (el *EasyLogger) Error(args ...interface{})

func (*EasyLogger) Errorf

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

func (*EasyLogger) Fatal

func (el *EasyLogger) Fatal(args ...interface{})

func (*EasyLogger) Fatalf

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

func (*EasyLogger) Flush

func (el *EasyLogger) Flush()

func (*EasyLogger) GetFlushTime

func (el *EasyLogger) GetFlushTime() int

func (*EasyLogger) GetLogHistory

func (el *EasyLogger) GetLogHistory() int

func (*EasyLogger) GetLogLevel

func (el *EasyLogger) GetLogLevel() string

func (*EasyLogger) GetLogPath

func (el *EasyLogger) GetLogPath() string

func (*EasyLogger) GetMode

func (el *EasyLogger) GetMode() int

func (*EasyLogger) Info

func (el *EasyLogger) Info(args ...interface{})

func (*EasyLogger) Infof

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

func (*EasyLogger) Printf

func (el *EasyLogger) Printf(format string, args ...interface{})

func (*EasyLogger) Println

func (el *EasyLogger) Println(args ...interface{})

func (*EasyLogger) SetLogLevel

func (el *EasyLogger) SetLogLevel(level string)

func (*EasyLogger) SetLogPath

func (el *EasyLogger) SetLogPath(logPath string)

func (*EasyLogger) SetLogToStderr

func (el *EasyLogger) SetLogToStderr(mode bool)

func (*EasyLogger) SetMode

func (el *EasyLogger) SetMode(mode int)

func (*EasyLogger) Warn

func (el *EasyLogger) Warn(args ...interface{})

func (*EasyLogger) Warnf

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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