Giter VIP home page Giter VIP logo

holmes's Introduction

Holmes

Golang logging package

installation

go get github.com/leesper/holmes

Usage

Add one line at the top of your main function, and you can do somg logging by calling such as holmes.Debug(...)

Features

  • Support creating new log file every hour/minute(rolling);
  • Can also print to stdout while writing to file;
  • Support levels: debug, info, warn, error, fatal;
  • Can change log file path by passing LogFilePath("./log") to holmes.Start()
  • Generating log files named PROGRAM.YYYY-MM-DD-HH-MM.PID.log
  • Support printing stacks of all go-routines when crashed

Things you can change

It is by default, a debug-level and print-to-stdout logger, you can pass parameters to change its behavior:

  • DebugLevel - change logger to debug level
  • InfoLevel - change logger to info level
  • WarnLevel - change logger to warn level
  • ErrorLevel - change logger to error level
  • FatalLevel - change logger to fatal level
  • LogFilePath - make logger write to disk file
  • EveryHour - logging to different file every hour
  • EveryMinute - logging to different file every minute
  • AlsoStdout - also logging to stdout
  • PrintStack - print stack infos of all go-routines when crashed
import "github.com/leesper/holmes"

func main() {
  // log files put in ./log, create new one every hour, also print to stdout
  defer holmes.Start(LogFilePath("./log"), EveryHour, AlsoStdout).Stop()
  holmes.Infof("%s", "If by life you were deceived,")
  holmes.Warnf("%s", "Don't be dismal, don't be wild!")
  holmes.Errorf("%s", "In the day of grief, be mild.")
  holmes.Infof("%s", "Merry days will come, believe.")
  ...
}
output:
2016/07/08 11:25:48  INFO [example.main] (example.go:48) - If by life you were deceived,
2016/07/08 11:25:48  WARN [example.main] (example.go:49) - Don't be dismal, don't be wild!
2016/07/08 11:25:48 ERROR [example.main] (example.go:50) - In the day of grief, be mild
2016/07/08 11:25:48  INFO [example.main] (example.go:51) - Merry days will come, believe.

Benchmark

BenchmarkFileLoggerSingleGoroutine-4  	  100000	     17694 ns/op
BenchmarkFileLoggerMultipleGoroutine-4	   50000	     37284 ns/op

holmes's People

Contributors

leesper avatar warnstar avatar

Watchers

James Cloos 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.