log

package module
v0.0.0-...-1025d31 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

README

log

light abstraction over https://github.com/inconshreveable/log15

Usage

Initialize it once in the main program as follows -

import "github.com/deep-compute/log"

func main() {
    quiet := True
    filename := "/tmp/test.log"
    level := "debug"

    hdlr, err := log.MakeBasicHandler(filename, level, quiet)
    if err != nil {
        panic(err)
    }

    log.SetHandler(hdlr)
}

All other packages need simply import and start logging wherever necessary

import "github.com/deep-compute/log"

func Foo() {
    log.Info("inside function Foo")
}

Documentation

Overview

log package enables simple levelled logging This is a thin wrapper around log15 which provides most of the functionality. We are wrapping primarily to not have to use "log15" as an import (which is just weird).

Index

Constants

This section is empty.

Variables

View Source
var BadConf error = errors.New("Bad configuration")
View Source
var Crit = log15.Crit
View Source
var Debug = log15.Debug
View Source
var Error = log15.Error
View Source
var Info = log15.Info
View Source
var New = log15.New
View Source
var Root = log15.Root
View Source
var Warn = log15.Warn

Functions

func Panicf

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

func Printf

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

func SetHandler

func SetHandler(hdlr Handler)

Types

type Ctx

type Ctx log15.Ctx

type Format

type Format log15.Format

func MakeFormatter

func MakeFormatter(format FormatConf) (Format, error)

MakeFormatter constructs a object of type Format based on the specified format conf and returns it Currently @format has to be a string with one of json | json_pretty | logfmt | terminal

type FormatConf

type FormatConf interface{}

type Handler

type Handler log15.Handler

func MakeBasicHandler

func MakeBasicHandler(fpath, lvl string, quiet bool) (Handler, error)

MakeBasicHandler prepares a log handler that writes to both a file at @fpath and stderr both with log level @lvl if @fpath is "", then it assumes it shouldn't write to a file and if @quiet is true, then it doesn't print to stderr

func MakeHandler

func MakeHandler(conf HandlerConf) (Handler, error)

MakeHandler accepts a handler configuration and constructs a usable

 handler. The handler config can be used to create sophistacted behavior
 by composing handlers as described here
 "https://godoc.org/gopkg.in/inconshreveable/log15.v2#Handler"

 A HandlerConf is a sequence of values of the following format
		[handlerType string, args ...interface{}]

     eg: HandlerConf{"file", "/tmp/test.log", "json"}
		In the above example, we have defined a file handler where the logs
		are to be written to the file "/tmp/test.log" in "json" format.

		Here is an example of a slightly more complex handler
		eg: HandlerConf{"level_filter", "debug",
				HandlerConf{"file", "/tmp/test.log", "json"},
			}
		In the above example, we defined a file handler just like above
		but in wrapping it with a "level_filter" handler, we've specified
		that only log statements that are greater than or equal to the
		specified level "debug".

	NOTE: for additional information about the following please
	refer to the godoc link placed above.

	List of handler formats:
		json
     json_pretty
		logfmt
		terminal

	List of handlers:

	- buffered (bufSize int, handler HandlerConf)
	- caller_file (handler HandlerConf)
	- caller_func (handler HandlerConf)
	- caller_stack (format string, handler HandlerConf)
	- discard ()
	- failover (handler ...HandlerConf)
 - file (path string, format string)
 - lazy (handler HandlerConf)
 - level_filter (level string, handler HandlerConf)
		level = debug | info | warn | error | crit
 - match_filter (key string, value string|int|float, handler HandlerConf)
	- multi (handler ...HandlerConf)
	- net (network string, address string, format string)
	- stream (stream string, format string)
		stream = stdout | stderr
	- sync (handler HandlerConf)
	- syslog (tag string, format string)
	- syslog_net (net string, address string, tag string, format string)
	- redis (ip_port string, channel string)
		`ip_port` is of the format "ip:port". port part is optional. on omission
			the default redis port 6379 is assumed.
		`channel` is the name of the redis channel to which the log statements
			are to be written.

func MakeNoopHandler

func MakeNoopHandler() (Handler, error)

MakeNoopHandler prepares a log handler that discards all the log statements that are sent to it

type HandlerConf

type HandlerConf []interface{}

type Lazy

type Lazy log15.Lazy

type LogToLog15

type LogToLog15 struct {
}

func (*LogToLog15) Write

func (p *LogToLog15) Write(b []byte) (n int, err error)

type Logger

type Logger log15.Logger

type Lvl

type Lvl log15.Lvl

type Record

type Record log15.Record

type RecordKeyNames

type RecordKeyNames log15.RecordKeyNames

type RedisHandler

type RedisHandler struct {
	Loc     string
	Channel string
	// contains filtered or unexported fields
}

func (*RedisHandler) Init

func (p *RedisHandler) Init() error

func (RedisHandler) Log

func (p RedisHandler) Log(r *log15.Record) error

Jump to

Keyboard shortcuts

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