lit

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

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

Go to latest
Published: Aug 13, 2019 License: BSD-2-Clause Imports: 7 Imported by: 37

README

lit logs, so hot.

GoDoc Go report Build Status Discord Gophers

lit is a Go package that provides

  • A very simple and opinionated message logger
  • Logging levels that allow you to set the verbosity of what is logged.
  • Added detail, such as file, line, and function name to each logged message.

For help with this package or general Go discussion, please join the Discord Gophers chat server.

Status @ 2019-03-02

This package is pretty much where it's going to be, there's a chance of some minor changes in the future but otherwise I expect it to remain about like it is now.

Design Goals

I find somethings, like logging, a bit tedious. So I wanted a way to have a very accessible logger that I could use anywhere without needing much setup.

So, lit has minimal configuration options, it doesn't require to be instantiated as a variable you pass around, or a global one you setup somewhere. You can just call the package functions from anywhere and there are handy methods for each of the four log levels it supports.

Usage

Add the package to your project.

Look around your code, and find a place that needs something logged.

If it's an error, just add a line like

lit.Error("message here, %s", err)

Now that error message will be logged.

If it's something kind of spammy and not even an error at all - just detail you need when debugging your application.

lit.Debug("message here")

Now that will be logged anytime your lit.LogLevel is set to lit.LogDebug.

There's also lit.Warning() and lit.Informational() methods that can be used similarly.

Options

lit.LogLevel

Can be set to lit.LogError, lit.LogWarning, lit.LogInformational, and lit.LogDebug. The default is lit.LogError.

lit.Prefix

Can be set to any string you want to prefix all logged messages. The default is LIT.

lit.Writer

This can be set to any io.Writer and that's where your logged messages will go. The default is os.Stderr.

Documentation

Index

Constants

View Source
const (

	// For unrecoverable errors where you would be unable to continue the
	// current scope of code.
	LogError int = iota

	// For non-critical errors that do not require you to abort/exit from the
	// current scope of code.
	LogWarning

	// For non-error "informational" logging.
	LogInformational

	// For any type of verbose debug specific logging.
	LogDebug
)

Error Levels that can be used to differentiate logged messages and also set the verbosity of logs to display.

Variables

View Source
var (
	// PrefixError is the custom prefix for errors
	PrefixError string

	// PrefixWarning is the custom prefix for warnings
	PrefixWarning string

	// PrefixInformational is the custom prefix for informational messages
	PrefixInformational string

	// PrefixDebug is the custom prefix for debug messages
	PrefixDebug string

	// Prefix is a string that is added to the start of any logged messages.
	Prefix string

	// LogLevel is the level of msgs to be logged.
	LogLevel int

	// Writer is the output io.Writer where messages are wrote to.
	Writer io.Writer
)

Functions

func Custom

func Custom(out io.Writer, level int, calldepth int, format string, a ...interface{})

Custom formats and writes the provided message to the defined io.Writer output as long as the passed level is less than or equal to the Logger.LogLevel

out       : io.Writer to output message to
level     : Log Level of the message being logged.
calldepth : Distance from the caller
format    : Printf style message format
a ...     : comma separated list of values to pass (like Printf)

func Debug

func Debug(format string, a ...interface{})

Debug logs a Debug level message

func Error

func Error(format string, a ...interface{})

Error logs a Error level message

func Info

func Info(format string, a ...interface{})

Info logs a Informational level message

func Warn

func Warn(format string, a ...interface{})

Warn logs a Warning level message

Types

This section is empty.

Jump to

Keyboard shortcuts

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