log

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: MIT Imports: 6 Imported by: 0

README

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")

Documentation

Index

Constants

View Source
const (
	ERROR    = Level(0x1)
	INFO     = Level(0x2)
	WARNING  = Level(0x4)
	DEBUG    = Level(0x8)
	CRITICAL = Level(0x10)
)
View Source
const (
	SHORT_TIMESTAMP = Flag(0x1)
	LONG_TIMESTAMP  = Flag(0x2)
)
View Source
const (
	ALL_LEVELS = ERROR | INFO | WARNING | DEBUG | CRITICAL
)
View Source
const (
	STD_FLAGS = SHORT_TIMESTAMP
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag int

type Level

type Level int

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	Printf(level Level, format string, args ...interface{}) error
	SetMask(mask Level)
	Flush() error
	Child(name string) Logger
	Dump(level Level, data []byte) error
}

func New

func New(name string, mask Level, flags Flag, outs []out.Outputter) Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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