Code Monkey home page Code Monkey logo

mo's Introduction

Mo

A leveled logger library for golang.

Features

  • Support level log
  • Support file line number
  • Support for distinguishing log modules
  • Support log colors
  • Support for custom formatting
go get github.com/mengdu/mo
package main
import (
	"github.com/mengdu/mo"
)

func main() {
	mo.Error("Error message")
	mo.Warn("Warn message")
	mo.Info("Warn message")
	mo.Log("Log message")
	mo.Success("Success message")
	mo.Debug("Debug message")
	mo.With(map[string]interface{}{
		"a": 1,
	}).Info("With meta message")
}

Example

Preview

Levels

LEVEL_NONE
LEVEL_ERROR
LEVEL_WARN
LEVEL_INFO
LEVEL_LOG
LEVEL_SUCCESS
LEVEL_DEBUG
LEVEL_ALL
logger := mo.New()
logger.Level = mo.LEVEL_ALL

Production recommendations

file, _ := os.OpenFile("service.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
errfile, _ := os.OpenFile("service-err.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
logger := mo.New()
logger.Formater = &mo.JsonForamter{}
logger.Stdout = file
logger.Stderr = errfile
logger.Level = mo.LEVEL_SUCCESS

Benchmark

go test -cpu=4 -benchmem -benchtime=5s -bench "^Benchmark"
goos: darwin
goarch: amd64
pkg: github.com/mengdu/mo
cpu: Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
BenchmarkNone-4                 1000000000               0.5773 ns/op          0 B/op          0 allocs/op
BenchmarkDefault-4              19812234               315.4 ns/op           384 B/op         15 allocs/op
BenchmarkWith-4                   936283              6774 ns/op            7416 B/op         68 allocs/op
BenchmarkWithTag-4               7291065               847.5 ns/op           464 B/op         23 allocs/op
BenchmarkCaller-4                5136397              1081 ns/op             800 B/op         25 allocs/op
BenchmarkFull-4                  3293016              1849 ns/op            2057 B/op         66 allocs/op
BenchmarkJsonForamter-4         12249668               497.5 ns/op           460 B/op          8 allocs/op
BenchmarkGoLog-4                12026568               464.6 ns/op           264 B/op          3 allocs/op
PASS
ok      github.com/mengdu/mo    48.118s

mo's People

Contributors

mengdu avatar

Watchers

 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.