Giter Club home page Giter Club logo

plogs's Introduction

Feature

  • 格式化日志输出
  • 异步输出日志到文件(终端采用同步输出)
  • 可通过WithWriter()添加自定义Writer
  • temp.log总是当前正在输出的日志文件
  • 日志输出级别可配置(默认输出所有级别的日志)
  • 日志文件切割方式: 达到指定大小后执行切割, 默认不切割
  • 提供日志文件保存时长设置: 超过该时长的文件将被删除, 默认不作删除操作
  • 日志级别划分: Panic(异常, 可以捕获), Fatal(致命错误), Error(错误), Warn(警告), Info(流水), Debug(调试信息)
  • 提供不同的日志记录方式: WriteByLevelSeparated(根据Level记录在不同的子目录下), WriteByLevelMerged(所有Level的日志记录在一起), WriteByBoth(单独记录与归并记录同时存在)

Usage

package main

import (
	"fmt"
	"time"

	"github.com/pyihe/go-pkg/tools"
	"github.com/pyihe/plogs"
)

func main() {
	opts := []plogs.Option{
		plogs.WithName("ALTIMA"),
		plogs.WithFileOption(plogs.WriteByLevelMerged),
		plogs.WithLogPath("./logs"),
		plogs.WithLogLevel(plogs.LevelFatal | plogs.LevelError | plogs.LevelWarn | plogs.LevelInfo | plogs.LevelDebug),
		plogs.WithStdout(true),
		plogs.WithMaxAge(24 * time.Hour),
		plogs.WithMaxSize(10 * 1024 * 1024),
	}

	logger := plogs.NewLogger(opts...)
	defer logger.Close()

	go func() {
		tag := time.Now()
		for n := 0; n < 3; n++ {
			for i := 1; i < 500000; i++ {
				plogs.Debugf("hello, this is level panic!")
				plogs.Infof("hello, this is level panic!")
				plogs.Warnf("hello, this is level panic!")
				plogs.Errorf("hello, this is level panic!")
			}
		}
		fmt.Printf("time consume: %v\n", time.Now().Sub(tag).Milliseconds())
	}()

	tools.Wait()
}

Terminal Screenshot

File Screenshot

Thanks

感谢Jetbrains开源开发许可证 提供的免费开发工具支持!

plogs's People

Contributors

pyihe avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.