Git Product home page Git Product logo

log's Introduction

The Go Log

Go Log is customizable modular log.

Download and Install

go get github.com/zooyer/log

Features

  • zero config, out of the box feature
  • customizable modular
  • high performance
  1. zero config

    package main
    
    import (
    	"github.com/zooyer/log"
    )
    
    func main() {
        // 0 config
    	log.D("debug message")   // 2019-10-28 23:07:56.369 DEBUG "debug message"
    	log.I("info message")    // 2019-10-28 23:07:56.369 INFO "info message"
    	log.W("warning message") // 2019-10-28 23:07:56.369 WARNING "warning message"
    	log.E("error message")   // 2019-10-28 23:07:56.369 ERROR "error message"
    }

    output:

    2019-10-28 23:07:56.369 DEBUG "debug message"
    2019-10-28 23:07:56.369 INFO "info message"
    2019-10-28 23:07:56.369 WARNING "warning message"
    2019-10-28 23:07:56.369 ERROR "error message"
  2. custom

    package main
    
    import (
    	"time"
    
    	"github.com/zooyer/log"
    )
    
    func main() {
    	// 1. create file rotating(default: size/time)
    	rotating := log.NewFileCountRotating(1024, 10)
    
    	// 2. create file recorder(default: terminal/file/network), custom formatter: json/text
    	recorder, err := log.NewFileRecorder("example.log", log.FormatJson, rotating)
    	if err != nil {
    		panic(err)
    	}
    	defer recorder.Close()
    
    	// 3. create logger, each level can be mapped to different recorder
    	logger := log.NewLogger()
    	logger.SetRecorder(recorder, "DEBUG", "INFO")
    	logger.SetDefault(recorder)
    
    	// 4. create log, logger's wrap
    	l := log.NewLog(logger)
    	l.Tag("id", "1001").Tag("type", "test").Debug("custom debug log")
    	l.Error("custom error log")
    
    	// 5. custom
    	var record = new(log.Record)
    	record.Time = time.Now()
    	record.Level = "record"
    	record.Message = "custom log"
    	record.Tag = make(log.Tag)
    	record.Tag["id"] = "1001"
    	record.Tag["type"] = "test"
    	logger.Record(record)
    }

    output:

    cat example.log
    {"level":"DEBUG","message":"custom debug log","tag":{"id":"1001","type":"test"},"time":"2019-10-28 23:41:34.385"}
    {"level":"ERROR","message":"custom error log","time":"2019-10-28 23:41:34.386"}
    {"level":"record","message":"custom log","tag":{"id":"1001","type":"test"},"time":"2019-10-28 23:41:34.386"}

log's People

Contributors

zooyer avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

lartry

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.