loggy

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2019 License: BSD-3-Clause Imports: 2 Imported by: 10

README

loggy

Go's worst logging package.

Go Report Card Build Status GoDoc NetflixOSS Lifecycle GitHub

Project Overview

Package loggy provides a simple logging library. It is focused on providing the bare minimum implementation of a leveled-logger for Go projects.

Getting Started

The loggy package can be installed by running:

$ go get gophers.dev/pkgs/loggy
Example Usage

A source file with this block

log := New("my-thing")
log.Tracef("this is trace %d", 1)
log.Infof("this is info %d", 2)
log.Warnf("this is warn %d", 3)
log.Errorf("this is error %d", 4)

Will produce output

2019/01/21 09:36:32 TRACE [my-thing] this is trace 1
2019/01/21 09:36:32 INFO  [my-thing] this is info 2
2019/01/21 09:36:32 WARN  [my-thing] this is warn 3
2019/01/21 09:36:32 ERROR [my-thing] this is error 4

Contributing

Package loggy is pretty minimalist, and so it's basically feature complete. Bug fixes and good ideas though are always welcome, please just file an issue.

License

The gophers.dev/pkgs/loggy module is open source under the BSD-3-Clause license.

Documentation

Overview

Package loggy provides a simple logging library for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Tracef(string, ...interface{})
	Infof(string, ...interface{})
	Warnf(string, ...interface{})
	Errorf(string, ...interface{})
}

A Logger is used to write log lines.

There are four methods for outputting a log message, each being associated with a different degree of urgency.

func Configure

func Configure(opts Options) Logger

Configure creates a Logger with the configured Options.

This allows for controlling the output destination of the created Logger.

func Discard

func Discard() Logger

Discard creates a Logger which throws away each statement.

func New

func New(prefix string) Logger

New creates a Logger which sends output to os.Stdout with each log line tagged with the given prefix.

To control the output destination, use Configure to create the Logger instead.

type Options

type Options struct {
	Prefix string
	Output Printer
}

Options allow for configuring a Logger, with the given Prefix and Output mechanism.

type Printer

type Printer interface {
	Printf(string, ...interface{})
}

A Printer is anything that can be used to Printf log messages.

The default underlying implementation of Logger provided by the loggy package defers to the standard library log package, which in turn provides an implementation of Printer that writes to an output file.

func Open

func Open(file *os.File) Printer

Open creates a standard library *log.Log with the given file as the underlying output device.

Jump to

Keyboard shortcuts

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