logo

package module
v0.0.0-...-781f026 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: MIT Imports: 5 Imported by: 0

README

logo=log+go 😀 用于golang微服务的分布式日志收集系统.

特性

  • 核心代码基于优秀的日志库logrus
  • TextFormatter提供了优秀的本地文件日志格式,同时提供适用于vscode的log文件高亮插件😎
  • JsonFormatter提供了适用于分布式日志收集的Json格式化功能
  • 提供从日志队列中读取日志并持久化到Fluent日志收集服务
  • 所有的持久化过程可选异步模式,不会阻塞当前业务goroutine,但在队列阻塞达到上限时会丢失
  • 只提供全局的Log对象,这有以下好处
    • 简化了竞争条件,提高效率
    • 程序日志的格式统一
    • 使用者方便
  • 提供了编译为C库的方案(export目录)

TODO

  1. 异步日志时使用channel,是否需要使用动态伸缩的队列替代
  2. TextFormatter 着色
  3. 更新软件设计图(docs)
  4. 提供统计/告警上报功能
  5. 完善测试文件
  6. 提供编译为java可用的方案(通过JNI)
  7. 提供日志收集系统完整的搭建方案和使用说明

Documentation

Index

Constants

View Source
const InvalidTID = ""

InvalidTID 无效的tracingID,代表该条日志tracingID无效

Variables

This section is empty.

Functions

func Debug

func Debug(traceID string, msg string, kv ...*Pair)

Debug log

func Error

func Error(traceID string, msg string, kv ...*Pair)

Error log

func Exit

func Exit()

Exit 安全退出

func Fatal

func Fatal(traceID string, msg string, kv ...*Pair)

Fatal log,without panic/exit

func Info

func Info(traceID string, msg string, kv ...*Pair)

Info log

func Log

func Log(e *Entry)

Log 执行格式化和持久化

func Notice

func Notice(traceID string, msg string, kv ...*Pair)

Notice log

func RegisterProcessors

func RegisterProcessors(caller, async bool, procs ...*Processor) bool

RegisterProcessors 注册处理器,一旦开始打日志就不能再调用! caller: 自动获取调用者信息(影响性能) async: 持久化日志时 使用异步的任务队列 procs: 一组包含 格式化器和持久化器组 的处理器组

func Trace

func Trace(traceID string, msg string, kv ...*Pair)

Trace log

func Warn

func Warn(traceID string, msg string, kv ...*Pair)

Warn warning log

Types

type Entry

type Entry struct {
	//Data 日志数据
	Data []*Pair

	// Time 日志创建时间
	Time time.Time

	// Level 本条日志所属级别
	Level Level

	// Caller 日志打印函数的调用方,包含 包名.函数(或文件名) 和行号
	Caller struct {
		File string
		Line int
	}

	// TraceID 日志的追踪ID,通常为用户名或事务ID等
	TraceID string

	// Message 日志的概述
	Message string
}

Entry 一条日志的所有信息

type Formotter

type Formotter interface {
	Format(*Entry) []byte
}

Formotter 格式化器,将日志转为[]byte

type Level

type Level int

Level 日志级别重定义

const (
	CloseLevel Level = iota
	FatalLevel
	ErrorLevel
	WarnLevel
	NoticeLevel
	InfoLevel
	DebugLevel
	TraceLevel
)

xxxLevel 日志级别定义,从1开始,0代表关闭

type Pair

type Pair struct {
	K string
	V interface{}
}

Pair 表示一对儿kv

func C

func C(k string, v interface{}) *Pair

C make a pair for call F/E/W...

type Persister

type Persister interface {
	// Level 设置当前输出等级
	SetLevel(Level)
	// Level 获取当前输出等级
	Level() Level
	// Send 日志持久化,应实现为阻塞且支持并发调用
	Send([]byte)
	// 在main函数退出前会调用,3s内保证不退出程序
	Close()
}

Persister 持久化日志 1.发送失败自己处理. 3.Close应当在尽量短的时间内返回

type Processor

type Processor struct {
	Formotter
	Persisters []Persister
}

Processor 日志处理器接口的包装器

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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