logger

package module
v0.0.0-...-af42e9a Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2016 License: BSD-2-Clause Imports: 0 Imported by: 8

README

go-logger

The only goal of this library is to provide a standard interface that can be used by library owners to allow passing a logger to their library.

Rationale

Quote from Why log.Logger is not an interface

In traditional programming languages, such as Java, the stdlib defines canonical interfaces that others can implement. Go stdlib does that too (...)

This is where I stop agreeing with the author of this post. Unfortunately Go creators didn't deem necessary to do this for logger, so it is impossible for library owners to allow passing a logger as a parameter to a library struct or function.

For example you could use logrus in your project, set it up to output JSON or to use one of the supported hooks but when using a library that needs to log some output you would suddenly be at the mercy of the library creator logger choice.

See I wish Logger was an interface and this reddit thread for reasons why the standard lib should provide a Logger interface.

Usage

Simply accept logger.Interface in your function or struct, and use one of the standard logger functions e.g. Println, Fatalf, Panic, etc.

Support

The interface is compatible with the standard logging libraries:

Author

Jerome Touffe-Blin, @jtblin, About me

License

go-logger is copyright 2015 Jerome Touffe-Blin and contributors. It is licensed under the BSD license. See the include LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	// Printf prints to the logger using the format.
	Printf(format string, v ...interface{})
	// Print prints to the logger.
	Print(v ...interface{})
	// Println prints new line.
	Println(v ...interface{})
	// Fatal is equivalent to Print() followed by a call to os.Exit(1).
	Fatal(v ...interface{})
	// Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
	Fatalf(format string, v ...interface{})
	// Fatalln is equivalent to Println() followed by a call to os.Exit(1).
	Fatalln(v ...interface{})
	// Panic is equivalent to Print() followed by a call to panic().
	Panic(v ...interface{})
	// Panicf is equivalent to Printf() followed by a call to panic().
	Panicf(format string, v ...interface{})
	// Panicln is equivalent to Println() followed by a call to panic().
	Panicln(v ...interface{})
}

Jump to

Keyboard shortcuts

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