holmes

package module
v0.0.0-...-307d8a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2019 License: Apache-2.0 Imports: 7 Imported by: 133

README

Holmes

Golang server logging package

GitHub forks GitHub stars GitHub license

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
Benchmark
BenchmarkFileLoggerSingleGoroutine-4  	  100000	     17694 ns/op
BenchmarkFileLoggerMultipleGoroutine-4	   50000	     37284 ns/op

Installation

go get -u -v 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(...)

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.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debugf

func Debugf(format string, v ...interface{})

Debugf prints formatted debug log.

func Debugln

func Debugln(v ...interface{})

Debugln prints debug log.

func Errorf

func Errorf(format string, v ...interface{})

Errorf prints formatted error log.

func Errorln

func Errorln(v ...interface{})

Errorln prints error log.

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf prints formatted fatal log and exits.

func Fatalln

func Fatalln(v ...interface{})

Fatalln prints fatal log and exits.

func Infof

func Infof(format string, v ...interface{})

Infof prints formatted info log.

func Infoln

func Infoln(v ...interface{})

Infoln prints info log.

func LogFilePath

func LogFilePath(p string) func(Logger) Logger

LogFilePath returns a function to set the log file path.

func Warnf

func Warnf(format string, v ...interface{})

Warnf prints formatted warn log.

func Warnln

func Warnln(v ...interface{})

Warnln prints warn log.

Types

type LogLevel

type LogLevel int

LogLevel is the log level type.

const (
	// DEBUG represents debug log level.
	DEBUG LogLevel = iota
	// INFO represents info log level.
	INFO
	// WARN represents warn log level.
	WARN
	// ERROR represents error log level.
	ERROR
	// FATAL represents fatal log level.
	FATAL
)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is the logger type.

func AlsoStdout

func AlsoStdout(l Logger) Logger

AlsoStdout sets log also output to stdio.

func DebugLevel

func DebugLevel(l Logger) Logger

DebugLevel sets log level to debug.

func ErrorLevel

func ErrorLevel(l Logger) Logger

ErrorLevel sets log level to error.

func EveryDay

func EveryDay(l Logger) Logger

EveryDay sets new log file created every day.

func EveryHour

func EveryHour(l Logger) Logger

EveryHour sets new log file created every hour.

func EveryMinute

func EveryMinute(l Logger) Logger

EveryMinute sets new log file created every minute.

func FatalLevel

func FatalLevel(l Logger) Logger

FatalLevel sets log level to fatal.

func InfoLevel

func InfoLevel(l Logger) Logger

InfoLevel sets log level to info.

func PrintStack

func PrintStack(l Logger) Logger

PrintStack sets log output the stack trace info.

func Start

func Start(decorators ...func(Logger) Logger) Logger

Start returns a decorated innerLogger.

func WarnLevel

func WarnLevel(l Logger) Logger

WarnLevel sets log level to warn.

func (Logger) Stop

func (l Logger) Stop()

Stop stops the logger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL