Skip to content
/ log Public

Simple logger for Go with several standard outputs

License

Notifications You must be signed in to change notification settings

avegner/log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

log

This a logger supporting the following outputs:

  • stderr
  • network (TCP, UDP, Unix networks)
  • file (zlib compression)
  • custom output

Installation

go get github.com/avegner/log

API

Logger has a very simple interface:

type Logger interface {
	Printf(level Level, format string, args ...interface{}) error
	SetMask(mask Level)
	Flush() error
	Child(name string) Logger
}
  • Printf - prints a log message with the given level
  • SetMask - sets enabled log levels
  • Flush - flushes all log outputs
  • Child - creates a child logger with the same parameters (mask, outputs, flags)

Each output supports the following interface:

type Outputter interface {
	io.Writer
	io.Closer
	Flush() error
}

There are standard outputs:

func NewNetOut(network, address string) (Outputter, error)

func NewFileOut(name string, perm os.FileMode, append bool, comprLevel int) (Outputter, error)

func NewStderrOut() (Outputter, error)

Any custom output implementing Outputter interface may be created.

To create a logger and a child logger:

// main scope
o, err := out.NewStderrOut()
if err != nil {
    // ...
}
mlog := log.New("main", log.ALL_LEVELS, log.STD_FLAGS, []out.Outputter{o})

// module scope
chlog := mlog.Child("module")