Logger - Go language is interface-oriented to implement an asynchronous log writing program

logger日志库

1、安装

go get github.com/staryjie/logger@latest

2、使用

示例:

package main

import (
	"github.com/staryjie/logger"
	"time"
)

func initLogger(name, logPath, logName, level, split_type string) (err error) {
	config := make(map[string]string)
	config["name"] = name
	config["log_path"] = logPath
	config["log_name"] = logName
	config["log_level"] = level
	config["log_split_type"] = split_type
	err = logger.InitLogger(name, config)
	if err != nil {
		return
	}
	logger.Trace("init logger success!")
	return
}

func Run() {
	for {
		logger.Fatal("User server is running...")
		time.Sleep(1 * time.Second)
	}

}

func main() {
	initLogger("file", "/var/log/", "user", "debug", "size")
	Run()
}

3、参数说明

name,           [file|console]  file: 写入文件, console: 输出日志到终端
log_path,       [str] 当`name``file`时需要传入,日志存放的路径
log_name,       [str] 当`name``file`时需要传入,日志文件名(不需要传入扩展名)
log_level,      [str] 日志级别,分别有 debug, trace, info, warn, error, fatal等
log_split_type, [str] 日志切割方式,默认是(file)按小时切割,如果需要按指定大小切割需要传入`size`和另一个参数`log_split_size`
log_split_size, [str] 日志切割大小,当日志文件大于等于该参数指定的值(B)时,进行切割,默认是100M,也就是 [104857600]

4、实现了哪些功能

  • 通过Go的channel将实时产生的日志写入到一个channel,然后另起一个线程从channel中读取日志消息,写入到文件中
  • 通过按小时进行日志文件切割或者指定日志大小进行文件切割
Similar Resources

A customized GORM logger that implements the appropriate interface and uses Logrus to output logs

CryptoMath GORM Logger A customized GORM logger that implements the appropriate interface and uses Logrus to output logs. Install go get github.com/ma

Nov 6, 2021

Go logger interface adapter

Glog glog is an abstraction for various Go language log libraries. The Logger interface is in maintenance-mode to prevent broken changes to projects b

Nov 17, 2021

Go-zla - Zerolog adapter to go-facades logger interface

GO-ZLA GO ZeroLog Adapter (a.k.a. go-zla) is a lightweight Golang module that ad

Feb 16, 2022

Structured log interface

Structured log interface Package log provides the separation of the logging interface from its implementation and decouples the logger backend from yo

Sep 26, 2022

A Go (golang) package providing high-performance asynchronous logging, message filtering by severity and category, and multiple message targets.

ozzo-log Other languages 简体中文 Русский Description ozzo-log is a Go package providing enhanced logging support for Go programs. It has the following fe

Dec 17, 2022

Seelog is a native Go logging library that provides flexible asynchronous dispatching, filtering, and formatting.

Seelog Seelog is a powerful and easy-to-learn logging framework that provides functionality for flexible dispatching, filtering, and formatting log me

Jan 3, 2023

Fully asynchronous, structured, pluggable logging for Go.

logr Logr is a fully asynchronous, contextual logger for Go. It is very much inspired by Logrus but addresses two issues: Logr is fully asynchronous,

Dec 28, 2022

A logger, for Go

Go-Log A logger, for Go! It's sort of log and code.google.com/p/log4go compatible, so in most cases can be used without any code changes. Breaking cha

Oct 7, 2022

Simple logger for Go programs. Allows custom formats for messages.

Simple logger for Go programs. Allows custom formats for messages.

go-logger A simple go logger for easy logging in your programs. Allows setting custom format for messages. Preview Install go get github.com/apsdehal/

Dec 17, 2022
Convenient Logger interface and std logger wrapper

Convenient logger interface and wrapper around std logger Interface type Logger interface { Error(err error) Debugf(format string, args ...interface

Nov 28, 2021
Logger - Simple logger without written with std pkg

Go-Logger Simple usage is: package main

Jan 2, 2022
Logger - A thin wrapper of uber-go/zap logger for personal project

a thin wraper of uber-go/zap logger for personal project 0. thanks uber-go/zap B

Sep 17, 2022
Binalyze logger is an easily customizable wrapper for logrus with log rotation

logger logger is an easily customizable wrapper for logrus with log rotation Usage There is only one function to initialize logger. logger.Init() When

Oct 2, 2022
Multi-level logger based on go std log

mlog the mlog is multi-level logger based on go std log. It is: Simple Easy to use NOTHING ELSE package main import ( log "github.com/ccpaging/lo

May 18, 2022
Secure logger in Go to avoid output sensitive data in log
Secure logger in Go to avoid output sensitive data in log

zlog A main distinct feature of zlog is secure logging that avoid to output secret/sensitive values to log. The feature reduce risk to store secret va

Dec 6, 2022
An golang log lib, supports tracking and level, wrap by standard log lib

Logex An golang log lib, supports tracing and level, wrap by standard log lib How To Get shell go get gopkg.in/logex.v1 source code import "gopkg.in/

Nov 27, 2022
Nginx-Log-Analyzer is a lightweight (simplistic) log analyzer for Nginx.
Nginx-Log-Analyzer is a lightweight (simplistic) log analyzer for Nginx.

Nginx-Log-Analyzer is a lightweight (simplistic) log analyzer, used to analyze Nginx access logs for myself.

Nov 29, 2022
Distributed-Log-Service - Distributed Log Service With Golang
Distributed-Log-Service - Distributed Log Service With Golang

Distributed Log Service This project is essentially a result of my attempt to un

Jun 1, 2022
Log-analyzer - Log analyzer with golang

Log Analyzer what do we have here? Objective Installation and Running Applicatio

Jan 27, 2022