ledger

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 7 Imported by: 5

README

Ledger

Build Status Go Reportcard GoDoc License Release

Ledger is a threadsafe, minimalist layer on top of native Go logging with the ability to write to more than standard out and honor log level thresholds.

Requirements

Golang v1.6 or higher

Versioning

The project will be versioned in accordance with Semver 2.0.0. See the releases section for the latest version. Until version 1.0.0 the SDK is considered to be unstable.

License

See LICENSE.md for more information.

Documentation

Overview

Package ledger provides a threadsafe, minimalist logger on top of native Go logging. Adding the ability to write to more than standard out and honor log level thresholds.

Example (Exported)

ExampleExported demonstrates the default exported logger

package main

import (
	"github.com/gomicro/ledger"
)

func main() {
	ledger.Debug("We've got a debug line here")
	ledger.Info("We've got a info line here")
	ledger.Warn("We've got a warn line here")
	ledger.Error("We've got a error line here")
	ledger.Fatal("We've got a fatal line here")
}
Output:

Example (Global)
package main

import (
	"os"

	"github.com/gomicro/ledger"
)

var (
	log *ledger.Ledger
)

func init() {
	log = ledger.New(os.Stdout, ledger.DebugLevel)
}

func main() {
	log.Debug("We've got a debug line here")
	log.Info("We've got a info line here")
	log.Warn("We've got a warn line here")
	log.Error("We've got a error line here")
	log.Fatal("We've got a fatal line here")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug writes a log entry with the debug log level

func Debugf

func Debugf(f string, args ...interface{})

Debugf writes a string formatted log entry with the debug log level

func EndpointDebug added in v0.0.4

func EndpointDebug(next http.Handler) http.Handler

EndpointDebug wraps the given http handler and logs details of the endpoint at the Debug threshold

func EndpointInfo added in v0.0.4

func EndpointInfo(next http.Handler) http.Handler

EndpointInfo wraps the given http handler and logs details of the endpoint at the Info threshold

func Error

func Error(args ...interface{})

Error writes a log entry with the error log level

func Errorf

func Errorf(f string, args ...interface{})

Errorf writes a string formatted log entry with the error log level

func Fatal

func Fatal(args ...interface{})

Fatal writes a log entry with the fatal log level

func Fatalf

func Fatalf(f string, args ...interface{})

Fatalf writes a string formatted log entry with the fatal log level

func Info

func Info(args ...interface{})

Info writes a log entry with the info log level

func Infof

func Infof(f string, args ...interface{})

Infof writes a string formatted log entry with the info log level

func Threshold added in v0.0.2

func Threshold(level Level)

Threshold sets the log level threshold for the exported logger

func Warn

func Warn(args ...interface{})

Warn writes a log entry with the warn log level

func Warnf

func Warnf(f string, args ...interface{})

Warnf writes a string formatted log entry with the warn log level

func Writer added in v0.1.1

func Writer(writer io.Writer)

Writer sets the writer for the exported logger

Types

type Ledger

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

Ledger represents a logger

func New

func New(w io.Writer, level Level) *Ledger

New returns a new Ledger configured with the specified writer and log level threshold

func (*Ledger) Debug

func (l *Ledger) Debug(args ...interface{})

Debug writes a log entry with the debug log level

func (*Ledger) Debugf

func (l *Ledger) Debugf(f string, args ...interface{})

Debugf writes a string formatted log entry with the debug log level

func (*Ledger) EndpointDebug added in v0.0.4

func (l *Ledger) EndpointDebug(next http.Handler) http.Handler

EndpointDebug wraps the given http handler and logs details of the endpoint at the Debug threshold

func (*Ledger) EndpointInfo added in v0.0.4

func (l *Ledger) EndpointInfo(next http.Handler) http.Handler

EndpointInfo wraps the given http handler and logs details of the endpoint at the Info threshold

func (*Ledger) Error

func (l *Ledger) Error(args ...interface{})

Error writes a log entry with the error log level

func (*Ledger) Errorf

func (l *Ledger) Errorf(f string, args ...interface{})

Errorf writes a string formatted log entry with the error log level

func (*Ledger) Fatal

func (l *Ledger) Fatal(args ...interface{})

Fatal writes a log entry with the fatal log level

func (*Ledger) Fatalf

func (l *Ledger) Fatalf(f string, args ...interface{})

Fatalf writes a string formatted log entry with the fatal log level

func (*Ledger) Info

func (l *Ledger) Info(args ...interface{})

Info writes a log entry with the info log level

func (*Ledger) Infof

func (l *Ledger) Infof(f string, args ...interface{})

Infof writes a string formatted log entry with the info log level

func (*Ledger) Threshold added in v0.0.2

func (l *Ledger) Threshold(level Level)

Threshold sets the log level threshold for the defined logger

func (*Ledger) Warn

func (l *Ledger) Warn(args ...interface{})

Warn writes a log entry with the warn log level

func (*Ledger) Warnf

func (l *Ledger) Warnf(f string, args ...interface{})

Warnf writes a string formatted log entry with the warn log level

type Level

type Level int8
const (
	FatalLevel Level = iota
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
)

func ParseLevel

func ParseLevel(lvl string) Level

func (Level) String

func (level Level) String() string

Jump to

Keyboard shortcuts

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