Help us shape the future of Go! Take the 2026 Go Developer Survey

logfox

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: Apache-2.0 Imports: 12 Imported by: 1

README

logfox

简介

logfox是一个简单的go log库,可以按小时自动切分日志,设置日志保存的期限

V1.1使用go mod做依赖管理

安装

go get github.com/zer0131/logfox

使用示例

package main

import "github.com/zer0131/logfox"

func init() {
    logfox.Init("./log", "test", "DEBUG", 7)
}

func main() {
    logfox.Info("test info")
    logfox.Close()
}

Documentation

Index

Constants

View Source
const (
	DEFAULT_FILEWRITER_MAX_EXPIRE_DAY          = 7                       //日志默认有效天数
	DEFAULT_FILEWRITER_FILE_SUFFIX_TIME_STRING = "2006010215"            //日志文件时间前缀
	DEFAULT_FILEWRITER_MSG_SUFFIX_TIME_STRING  = "06-01-02 15:04:05.999" //日志时间格式
	LogIDKey                                   = "log-id"
)

Variables

This section is empty.

Functions

func Close

func Close()

func Debug

func Debug(v ...interface{})

func DebugWithContext added in v1.2.0

func DebugWithContext(ctx context.Context, v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func DebugfWithContext added in v1.2.0

func DebugfWithContext(ctx context.Context, format string, v ...interface{})

func Error

func Error(v ...interface{})

func ErrorWithContext added in v1.2.0

func ErrorWithContext(ctx context.Context, v ...interface{})

func Errorf

func Errorf(format string, v ...interface{})

func ErrorfWithContext added in v1.2.0

func ErrorfWithContext(ctx context.Context, format string, v ...interface{})

func GenLogId added in v1.2.0

func GenLogId() string

func Info

func Info(v ...interface{})

func InfoWithContext added in v1.2.0

func InfoWithContext(ctx context.Context, v ...interface{})

func Infof

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

func InfofWithContext added in v1.2.0

func InfofWithContext(ctx context.Context, format string, v ...interface{})

func Init

func Init(path string, app string, level string, expireDay int) error

日志初始化

func LogIdFromContext added in v1.2.0

func LogIdFromContext(ctx context.Context) (string, bool)

func NewContextWithHttpReq added in v1.2.0

func NewContextWithHttpReq(ctx context.Context, r *http.Request) context.Context

func NewContextWithLogID added in v1.2.0

func NewContextWithLogID(ctx context.Context) context.Context

func NewContextWithSpecifyLogID added in v1.2.0

func NewContextWithSpecifyLogID(ctx context.Context, logId string) context.Context

func NewGrpcContextWithLogID added in v1.2.0

func NewGrpcContextWithLogID(ctx context.Context) context.Context

func Notice

func Notice(v ...interface{})

func NoticeWithContext added in v1.2.0

func NoticeWithContext(ctx context.Context, v ...interface{})

func Noticef

func Noticef(format string, v ...interface{})

func NoticefWithContext added in v1.2.0

func NoticefWithContext(ctx context.Context, format string, v ...interface{})

func Panic

func Panic(v ...interface{})

func PanicWithContext added in v1.2.0

func PanicWithContext(ctx context.Context, v ...interface{})

func Panicf

func Panicf(format string, v ...interface{})

func PanicfWithContext added in v1.2.0

func PanicfWithContext(ctx context.Context, format string, v ...interface{})

func Warn

func Warn(v ...interface{})

func WarnWithContext added in v1.2.0

func WarnWithContext(ctx context.Context, v ...interface{})

func Warnf

func Warnf(format string, v ...interface{})

func WarnfWithContext added in v1.2.0

func WarnfWithContext(ctx context.Context, format string, v ...interface{})

Types

type Level

type Level uint8

别名

const (
	DebugLevel Level = iota
	InfoLevel
	NoticeLevel
	WarnLevel
	ErrorLevel
	PanicLevel
)

级别常量

func (Level) String

func (l Level) String() string

实现String方法,输出时默认转换为字符串

type Logger

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

func NewLogger

func NewLogger(path string, app string, expireDay int, fileSuffixTimeString string) (*Logger, error)

func (*Logger) Close

func (lo *Logger) Close()

func (*Logger) Output

func (lo *Logger) Output(msg string, level Level)

正常输出

func (*Logger) OutputWf

func (lo *Logger) OutputWf(msg string, level Level)

错误输出

type Writer

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

func NewWriter

func NewWriter(path string, fileName string, fileSuffixTimeString string, expireDay int) (*Writer, error)

func (*Writer) Close

func (w *Writer) Close()

Jump to

Keyboard shortcuts

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