logker

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: MIT Imports: 9 Imported by: 0

README

LogKer

LogKer It's a log Library of Golang. It's easy to use.👨‍💻‍

📚中文说明 | 🤩Document | 👨‍💻‍ Release


Features

  • Support file backup.
  • Simple and easy to use.
  • Support file storage log.
  • Support console color printing.
  • Custom log file storage location.
  • Support setting time and time zone.
  • Support log file size for split storage.
  • Error level output to specified file separately.
  • Four levels of debug info error warning are supported.
  • Future support: The remote computer stores the socket output🙏.
  • The project is constantly maintained and updated. I like 😍A kind of Please click star Thanks♪(・ω・)ノ!
  • Is this you?😜

Upgrade List

  • v1.1.5 Support for custom message formats.(SerialVersion) issues1
  • v1.1.8 Support coroutine to record logs,The code base is smaller and lighter(AsynchronousProcessingVersion).

Historical Documents

The Documents version is v1.1.8

Installation

🔝 The minimum requirement of Go version is 1.11. 🔝 Your project also uses go module!!!

go get github.com/higker/logker

OR

go get -u github.com/higker/logker

command add -u flag to update in the future.

Use Example

1. File Logger
package main

import (
	klog "github.com/higker/logker"
	"time"
)

func main() {
	// Specify file location! Create folder in advance!!
	dir := "/Users/ding/Documents/test_log"
	// New file logger
	// File Max size : You can also use built-in constants
	// klog.GB1  	= 1GB
	// klog.MB10  	= 10MB
 	// klog.MB100	= 100MB
	format := "{level} - DATE {time}  - POS {position} - MSG {message}" //This version was modified from v 1.1.5
	//Create Log Buffer
    	task := InitAsync(Qs1w)
   	flog,e := klog.NewFlog(klog.DEBUG, true, klog.Shanghai, dir, "log", 10*1024, 0777,format,task)
    	if e != nil{
       	    .... //Custom Operation
   	}
	// Analog output log
	for {
		flog.Debug("DEBUG : %d + %d = %d",1,2,1+2)
		flog.Error("ERROR")
		flog.Warning("WARNING %p",flog)
		flog.Info("INFO %s","Hello LogKer.")
		time.Sleep(2 * time.Second)
	}
}

👆Parameter note List:


// Build File logger
// Args note
// logLevel:    lev,       \\ logging level
// wheError:    wheErr,    \\ whether enable  error alone file
// directory:   dir,	   \\ logging file save directory
// fileName:    fileName,  \\ logging save file name
// timeZone:    zone,	   \\ load time zone format
// power:       power,     \\ file system power
// fileMaxSize: size,      \\ logging alone file max size
// task := InitAsync(Qs1w) \\ createsABufferForCoroutineLogProcessing
// format :
	// Now upgrade to version v 1.1.5 to customize the message output format ~
	// TheCustomTagNameMustBe {level} {time} {position} {message}
	// The location of the custom label is the location
	// where the program outputs the corresponding log message at run time!!!!
	// forExampleHereIsMyCustom
	// 1. //format := "{level} - {time} - {position} - {message}"
2. Console Logger

package main

import (
	"github.com/higker/logker"
	"strings"
)

//type Formatting string

// logKer library Test
func main() {
	// Now upgrade to version v 1.1.5 to customize the message output format ~
	// TheCustomTagNameMustBe {level} {time} {position} {message}
	// The location of the custom label is the location
	// where the program outputs the corresponding log message at run time!!!!
	// forExampleHereIsMyCustom
	// 1. //format := "{level} - {time} - {position} - {message}"
	format := "{level} - 时间 {time}  - 位置 {position} - 消息 {message}" //This version was modified from v 1.1.5
    	//Create Log Buffer
    	task := InitAsync(Qs1w)
	log,e := logker.NewClog(logker.DEBUG, logker.Shanghai, format,task)
    	if e != nil{
        	..... //Custom Operation
    	}
	log.Debug("DEBUG %s","自定义日志消息匹配符测试")
	log.Info("%v", log)
	log.Warning("%v", logker.Shanghai)
	log.Error("ERROR")
}

OutPut

[ DEBUG ] - 时间 2020-04-20 11:57:23.8927  - 位置 main.go|main.main:23 - 消息 DEBUG 自定义日志消息匹配符测试
[  INFO ] - 时间 2020-04-20 11:57:23.8928  - 位置 main.go|main.main:24 - 消息 &{0 Asia/Shanghai 0xc00008e220 {level} - 时间 {t位置 {position} - 消息 {message}}
[WARNING] - 时间 2020-04-20 11:57:23.8928  - 位置 main.go|main.main:25 - 消息 Asia/Shanghai
[ ERROR ] - 时间 2020-04-20 11:57:23.8929  - 位置 main.go|main.main:26 - 消息 ERROR

3. Effect:

The screenshot is not updated ~ The current screenshot is v1.0.9 version, you can install the library yourself to see the effect. LogKerGolang

log,golang,logKer

Thank list🤝

Other

License

This project open source is MIT License . See the LICENSE file content.

Documentation

Overview

LogKer for Golang simple logging library.

Copyright (c) 2020 SDing <deen.job@qq.com>

Open Source: MIT License.

Use Video : https://www.bilibili.com/video/BV1WZ4y1s7zD?t=2

The simplest way to use LogKer is simply the package-level exported logger:

Console Logging :

  package main

  import (
    klog "github.com/higker/logker"
  )

  func main() {
		// Custom logging message template
		format := "{level} - 时间 {time}  - 位置 {position} - 消息 {message}"
		// Create Log Buffer
		task := klog.InitAsync(klog.Qs1w)
		log,e := klog.NewClog(klog.DEBUG, klog.Shanghai,format,task)
 		if e != nil{
			// .... Custom Operation
		}
		// Analog output log
		for {
			log.Debug("DEBUG %s","自定义日志消息匹配符测试")
			log.Info("%v", log)
			log.Warning("%v", logker.Shanghai)
			log.Error("ERROR")
		}
  }

Output:

[ DEBUG ] - 时间 2020-04-20 11:57:23.8927  - 位置 main.go|main.main:23 - 消息 DEBUG 自定义日志消息匹配符测试
[  INFO ] - 时间 2020-04-20 11:57:23.8928  - 位置 main.go|main.main:24 - 消息 &{0 Asia/Shanghai 0xc00008e220 {level} - 时间 {t位置 {position} - 消息 {message}}
[WARNING] - 时间 2020-04-20 11:57:23.8928  - 位置 main.go|main.main:25 - 消息 Asia/Shanghai
[ ERROR ] - 时间 2020-04-20 11:57:23.8929  - 位置 main.go|main.main:26 - 消息 ERROR

File Logging :

	package main

	import (
		klog "github.com/higker/logker"
		"time"
	)

	func main() {
		// Specify file location! Create folder in advance!!
		dir := "/Users/ding/Documents/test_log"
		// New file logger
		// File Max size : You can also use built-in constants
		// klog.GB1  	= 1GB
		// klog.MB10  	= 10MB
 		// klog.MB100	= 100MB
		format := "{level} - DATE {time}  - POS {position} - MSG {message}"
		// Create Log Buffer
		task := klog.InitAsync(klog.Qs1w)
   		flog,e := klog.NewFlog(klog.DEBUG, true, klog.Shanghai, dir, "log", 10*1024, 0777,format,task)
		if e != nil{
			// ... Custom Operation
   		}
		// Analog output log
		for {
			flog.Debug("DEBUG : %d + %d = %d",1,2,1+2)
			flog.Error("ERROR")
			flog.Warning("WARNING %p",flog)
			flog.Info("INFO %s","Hello LogKer.")
			time.Sleep(2 * time.Second)
		}
	}

Output File:

log.log
error_log.log
log_2020_05_01_14_06_05.6390_bak.log
error_2020_05_01_14_06_16.4008_bak.log

For a full guide visit https://github.com/higker/logker

Index

Constants

View Source
const (

	// 10000  BufferSize
	Qs1w = 10000 * iota
	// 20000  BufferSize
	Qs2w
	// 30000  BufferSize
	Qs3w
	// 40000  BufferSize
	Qs4w
	// 50000  BufferSize
	Qs5w
	// 60000  BufferSize
	Qs6w
)

Channel Buffer Size

View Source
const (
	// Log file size
	// You can also customize. Unit is kb.
	MB10  int64 = 10 * 1024 * 1024
	MB100 int64 = 100 * 1024 * 1024
	GB1   int64 = 10 * MB100
)
View Source
const (
	// Debug level
	DEBUG level = iota
	// Info level
	INFO
	// Warning level
	WARNING
	// Error level
	ERROR
)

Logging level

View Source
const (
	//https://blog.imdst.com/guo-bf/
	//美东     EST         /usr/share/zoneinfo/EST5EDT
	//美西     PST         /usr/share/zoneinfo/PST8PDT
	//澳洲     CST         /usr/share/zoneinfo/CST6CDT
	//欧洲     GMT         /usr/share/zoneinfo/Europe/London
	//泰国     Thailand    /usr/share/zoneinfo/Asia/Bangkok
	//越南     Vietnam     /usr/share/zoneinfo/Asia/Ho_Chi_Minh
	//新加坡   Singapore   /usr/share/zoneinfo/Asia/Singapore
	//台湾     Taiwan      /usr/share/zoneinfo/Asia/Taipei
	//香港     HongKong    /usr/share/zoneinfo/Asia/Hong_Kong
	//日本     Japan       /usr/share/zoneinfo/Asia/Tokyo
	//韩国     Korea       /usr/share/zoneinfo/Asia/Pyongyang
	EST       logTimeZone = "EST5EDT"
	PST       logTimeZone = "PST8PDT"
	CST       logTimeZone = "CST6CDT"
	GMT       logTimeZone = "Europe/London"
	Thailand  logTimeZone = "Asia/Bangkok"
	Vietnam   logTimeZone = "Asia/Ho_Chi_Minh"
	Singapore logTimeZone = "Asia/Singapore"
	Taiwan    logTimeZone = "Asia/Taipei"
	HongKong  logTimeZone = "Asia/Hong_Kong"
	Japan     logTimeZone = "Asia/Tokyo"
	Korea     logTimeZone = "Asia/Pyongyang"
	Shanghai  logTimeZone = "Asia/Shanghai" // Shanghai

)
View Source
const (
	// Log message format wildcards
	// {level} == logging level
	// {time} == time
	// {position} == runtime caller info
	// {message} == logging message
	// This was modified for v 1.1.5
	// OutPut: [INFO] 2006-01-02 13:05.0006 MP - Position: test.go|main.test:21 - Message: news
	DefaultFormat = "{level} - Date: {time}  {position} - Message: {message}"
)
View Source
const Version = "1.2.2"

This is package version

Variables

View Source
var (
	SKIP = 3
)

Runtime caller skip

Functions

func Debug added in v1.2.0

func Debug(value string, arg ...interface{})

Debug level log

func Error added in v1.2.0

func Error(value string, arg ...interface{})

Error level log

func Info added in v1.2.0

func Info(value string, arg ...interface{})

Info level log

func Warning added in v1.2.0

func Warning(value string, arg ...interface{})

Warning level log

Types

type Async added in v1.1.6

type Async interface {
	// contains filtered or unexported methods
}

Asynchronous Task Interface added after v1.1.6

type AsyncTask added in v1.1.6

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

Asynchronous Task Processing

func InitAsync added in v1.1.6

func InitAsync(queueSize int64) *AsyncTask

Initializes The Logging Producer Channel Buffer Queue Size Data Type int64

type ByteSize added in v1.1.6

type ByteSize float64

ByteSize

const (
	KB ByteSize = 1 << (10 * iota)
	MB
	GB
	TB
	PB
	EB
	ZB
	YB
)

ByteSize

type Logger

type Logger interface {
	// Info level log
	Info(value string, arg ...interface{})
	// Debug level log
	Debug(value string, arg ...interface{})
	// Error level log
	Error(value string, arg ...interface{})
	// Warning level log
	Warning(value string, arg ...interface{})
}
var Log Logger

Log logger

func NewClog

func NewClog(lev level, zone logTimeZone, formatting string, at *AsyncTask) (Logger, error)

Build console Logger

lev : Logging level
zone : Logging time zone
formatting : Logging format template string
at : AsyncTask Pointer

func NewFlog

func NewFlog(lev level, wheErr bool, zone logTimeZone, dir string, fileName string, size int64, power os.FileMode, formatting string, at *AsyncTask) (Logger, error)

Build File logger

lev : Logging level
zone : Logging time zone
formatting : Logging format template string
at : AsyncTask Pointer
wheErr : Whether To Open A Separate ErrorFile
dir : Logging file output directory
fileName : Logging Name
size : File size
power : File system power

Jump to

Keyboard shortcuts

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