Gllog

package module
v0.0.0-...-cac0887 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT Imports: 14 Imported by: 0

README

Gllog

全世界最烂的Go语言日志库 (支持Windows、Linux、MacOS日志的美化彩色终端输出,支持输出中定位Go源码、方法、输出行行号位置定位,支持写出日志文件)

功能模块
  • 支持 Windows、Linux、macOS三种系统的终端美化输出
  • 支持控制台终端彩色输入
  • 支持定位输出所在的Go源码文件、方法名、发生时间、行号等
  • 支持日志指定输出到磁盘文件
使用方法

🧐一看就会 一做就对🥳

package main

import "github.com/lfoder/Gllog"

// 需要先实例化一个对象 Option可选
var log = Gllog.New(&Gllog.Options{
	DebugMode:true,		// 若 DebugMode 为 True 则 控制台终端将输出详细调试信息,默认显示输出行所在的GO源码文件及行号
	// DebugMode开启时 下面两项才可用
	ShowDateTime:true,  // 是否在终端显示日志事件发生时间
	ShowFuncName:true,  // 是否在终端显示日志事件发生所在的函数功能模块
	LogOutFilePath:`log/xx.log`,  // 输入日志文件位置,只要路径不指定就不会输出日志文件 指定 则 输出日志文件(路径目录不存在会自动创建)
})

func main() {
	testFunc()
}

func testFunc(){
	// Simple 输出 (默认色)
	log.Print("Print 日志输出测试 (需要自己加\\n换行) \n")
	log.Println("Println 日志输出测试 (自动换行)")
	log.Printf("Printf 日志输出测试 (%s) \n","支持格式化输出, 需要自己加\\n换行")
	log.Printfln("Printfln 日志输出测试 (%s)","自动换行 + 支持格式化输出")
	// Success 输出 (绿色)
	log.SuccessPrint("SuccessPrint 日志输出测试 (需要自己加\\n换行) \n")
	log.SuccessPrintln("SuccessPrintln 日志输出测试 (自动换行)")
	log.SuccessPrintf("SuccessPrintf 日志输出测试 (%s) \n","支持格式化输出, 需要自己加\\n换行")
	log.SuccessPrintfln("SuccessPrintfln 日志输出测试 (%s)","自动换行 + 支持格式化输出")
	// Info 输出 (青色)
	log.InfoPrint("InfoPrint 日志输出测试 (需要自己加\\n换行) \n")
	log.InfoPrintln("InfoPrintln 日志输出测试 (自动换行)")
	log.InfoPrintf("InfoPrintf 日志输出测试 (%s) \n","支持格式化输出, 需要自己加\\n换行")
	log.InfoPrintfln("InfoPrintfln 日志输出测试 (%s)","自动换行 + 支持格式化输出")
	// Warn 输出 (黄色)
	log.WarnPrint("WarnPrint 日志输出测试 (需要自己加\\n换行) \n")
	log.WarnPrintln("WarnPrintln 日志输出测试 (自动换行)")
	log.WarnPrintf("WarnPrintf 日志输出测试 (%s) \n","支持格式化输出, 需要自己加\\n换行")
	log.WarnPrintfln("WarnPrintfln 日志输出测试 (%s)","自动换行 + 支持格式化输出")
	// Error 输出 (红色)
	log.ErrorPrint("ErrorPrint 日志输出测试 (需要自己加\\n换行) \n")
	log.ErrorPrintln("ErrorPrintln 日志输出测试 (自动换行)")
	log.ErrorPrintf("ErrorPrintf 日志输出测试 (%s) \n","支持格式化输出, 需要自己加\\n换行")
	log.ErrorPrintfln("ErrorPrintfln 日志输出测试 (%s)","自动换行 + 支持格式化输出")
}
全平台编译
  • Windows 编译
GOOS=windows GOARCH=amd64 go build -i -ldflags "-s -w" -o test_windows_amd64.exe test.go 
GOOS=windows GOARCH=386 go build -i -ldflags "-s -w" -o test_windows_386.exe test.go
  • Linux 编译
GOOS=linux GOARCH=amd64 go build -i -ldflags "-s -w" -o test_linux_amd64 test.go
GOOS=linux GOARCH=386 go build -i -ldflags "-s -w" -o test_linux_386 test.go
GOOS=linux GOARCH=arm go build -i -ldflags "-s -w" -o test_linux_arm test.go
  • macOS 编译
GOOS=darwin GOARCH=amd64 go build -i -ldflags "-s -w" -o test_darwin_amd64 test.go
GOOS=darwin GOARCH=386 go build -i -ldflags "-s -w" -o test_darwin_386 test.go
全平台测试

⬇️正常模式⬇️

image-20190301141029690

⬇️调试模式⬇️

image-20190301141200939

  • Windows 测试

    • Windows XP

    • Windows 7

    • Windows 10

  • Linux 测试

    • CentOS 7

      image-20190301140523534

  • macOS 测试

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SlowQueryLogger = log.StandardLogger()

SlowQueryLogger is used to log slow query, InitLogger will modify it according to config file.

Functions

func InitLogger

func InitLogger(cfg *LogConfig) error

InitLogger initalizes PD's logger.

Types

type FileLogConfig

type FileLogConfig struct {
	// Log filename, leave empty to disable file log.
	Filename string `toml:"filename" json:"filename"`
	// Is log rotate enabled.
	LogRotate bool `toml:"log-rotate" json:"log-rotate"`
	// Max size for a single file, in MB.
	MaxSize int `toml:"max-size" json:"max-size"`
	// Max log keep days, default is never deleting.
	MaxDays int `toml:"max-days" json:"max-days"`
	// Maximum number of old log files to retain.
	MaxBackups int `toml:"max-backups" json:"max-backups"`
}

FileLogConfig serializes file log related config in toml/json.

type Llog

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

func New

func New(option ...*Options) *Llog

func (*Llog) ErrorPrint

func (L *Llog) ErrorPrint(i ...interface{})

*************** Error Print Start *****************

func (*Llog) ErrorPrintf

func (L *Llog) ErrorPrintf(format string, i ...interface{})

func (*Llog) ErrorPrintfln

func (L *Llog) ErrorPrintfln(format string, i ...interface{})

func (*Llog) ErrorPrintln

func (L *Llog) ErrorPrintln(i ...interface{})

func (*Llog) InfoPrint

func (L *Llog) InfoPrint(i ...interface{})

*************** Info Print Start *****************

func (*Llog) InfoPrintf

func (L *Llog) InfoPrintf(format string, i ...interface{})

func (*Llog) InfoPrintfln

func (L *Llog) InfoPrintfln(format string, i ...interface{})

func (*Llog) InfoPrintln

func (L *Llog) InfoPrintln(i ...interface{})

func (*Llog) Print

func (L *Llog) Print(i ...interface{})

*************** Simple Print Start *****************

func (*Llog) Printf

func (L *Llog) Printf(format string, i ...interface{})

func (*Llog) Printfln

func (L *Llog) Printfln(format string, i ...interface{})

func (*Llog) Println

func (L *Llog) Println(i ...interface{})

func (*Llog) SuccessPrint

func (L *Llog) SuccessPrint(i ...interface{})

*************** Success Print Start *****************

func (*Llog) SuccessPrintf

func (L *Llog) SuccessPrintf(format string, i ...interface{})

func (*Llog) SuccessPrintfln

func (L *Llog) SuccessPrintfln(format string, i ...interface{})

func (*Llog) SuccessPrintln

func (L *Llog) SuccessPrintln(i ...interface{})

func (*Llog) WarnPrint

func (L *Llog) WarnPrint(i ...interface{})

*************** Warn Print Start *****************

func (*Llog) WarnPrintf

func (L *Llog) WarnPrintf(format string, i ...interface{})

func (*Llog) WarnPrintfln

func (L *Llog) WarnPrintfln(format string, i ...interface{})

func (*Llog) WarnPrintln

func (L *Llog) WarnPrintln(i ...interface{})

type LogConfig

type LogConfig struct {
	// Log level.
	Level string `toml:"level" json:"level"`
	// Log format. one of json, text, or console.
	Format string `toml:"format" json:"format"`
	// Disable automatic timestamps in output.
	DisableTimestamp bool `toml:"disable-timestamp" json:"disable-timestamp"`
	// File log config.
	File FileLogConfig `toml:"file" json:"file"`
	// SlowQueryFile filename, default to File log config on empty.
	SlowQueryFile string
}

LogConfig serializes log related config in toml/json.

type Options

type Options struct {
	DebugMode      bool // 开启后 将打印输出行在源码详细的位置信息
	ShowDateTime   bool
	ShowFuncName   bool
	LogOutFilePath string // 指定路径 则写出日志到文件
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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