Je kunt niet meer dan 25 onderwerpen selecteren Onderwerpen moeten beginnen met een letter of nummer, kunnen streepjes bevatten ('-') en kunnen maximaal 35 tekens lang zijn.
Stephen Searles b8923b6c6d added Stderr 8 jaren geleden
log.go added Stderr 8 jaren geleden
readme.md initial commit 8 jaren geleden

readme.md

log

-- import "git.stephensearles.com/stephen.searles/log"

Package log implements logging with two levels: info and debug. This distillation implements Dave Cheney's recommendation in his blog post, "Let's talk about logging" [1]. The methods provided are intended to mimic the most useful parts of the fmt and log standard packages.

The easiest way to use this package is to just call the top-level Print-ish and Debug-ish functions. If you need to write to another writer than Stdout, replace Default:

log.Default = log.Writer(myWriter, "[DEBUG]", "[INFO]")

If you want to, say, write to two files for the two levels, implement Interface. For an example, see how the Writer function is implemented.

[1] http://dave.cheney.net/2015/11/05/lets-talk-about-logging

Usage

var (
	// Stdout is os.Stdout wrapped as an Interface.
	Stdout = Writer(os.Stdout, "[debug]", "[info]")

	// Default is a Log that writes to Stdout.
	Default = Log{Stdout}
)

func Debug

func Debug(v ...interface{})

Debug writes to the default logger. Arguments are handled in the manner of fmt.Sprint.

func Debugf

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

Debugf writes to the default logger. Arguments are handled in the manner of fmt.Sprintf.

func Debugln

func Debugln(v ...interface{})

Debugln writes to the default logger. Arguments are handled in the manner of fmt.Sprintln.

func Print

func Print(v ...interface{})

Print writes to the default logger. Arguments are handled in the manner of fmt.Sprint.

func Printf

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

Printf writes to the default logger. Arguments are handled in the manner of fmt.Sprintf.

func Println

func Println(v ...interface{})

Println writes to the default logger. Arguments are handled in the manner of fmt.Sprintln.

type Interface

type Interface interface {
	Print(s string)
	Debug(s string)
}

Interface is the set of methods implemented by custom loggers for outputting data. An implementation of Interface could, for instance, write Debug messages to a file and send Print statements both to a file and to an IRC channel.

func Writer

func Writer(w io.Writer, debug, info string) Interface

Writer returns an Interface with the given debug and info prefixes that write to w.

type Log

type Log struct {
	Interface
}

Log provides standard logging methods from a custom Interface. The zero value uses Stdout.

func (Log) Debug

func (l Log) Debug(v ...interface{})

Debug writes to l.Interface, or Stdout if l.Interface is nil. Arguments are handled in the manner of fmt.Sprint.

func (Log) Debugf

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

Debugf writes to l.Interface, or Stdout if l.Interface is nil. Arguments are handled in the manner of fmt.Sprintf.

func (Log) Debugln

func (l Log) Debugln(v ...interface{})

Debugln writes to l.Interface, or Stdout if l.Interface is nil. Arguments are handled in the manner of fmt.Sprintln.

func (Log) Print

func (l Log) Print(v ...interface{})

Print writes to l.Interface, or Stdout if l.Interface is nil. Arguments are handled in the manner of fmt.Sprint.

func (Log) Printf

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

Printf writes to l.Interface, or Stdout if l.Interface is nil. Arguments are handled in the manner of fmt.Sprintf.

func (Log) Println

func (l Log) Println(v ...interface{})

Println writes to l.Interface, or Stdout if l.Interface is nil. Arguments are handled in the manner of fmt.Sprintln.