Help us shape the future of Go! Take the 2026 Go Developer Survey

logm

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2018 License: MIT Imports: 4 Imported by: 5

README

logm

Logm is a fairly simple logger that supports log levels and colored output (inspired by gin-gonic/gin's logger).

Usage

go get this package:

go get github.com/mc0239/logm

Make a new logger:

// making a logger with prefix
logger := logm.New("my-logger")

// making a logger with prefix and custom output (pass io.Writer)
logger := logm.NewWithOutput(os.Stdout, "my-logger")

Log a message:

logger.Verbose("Verbose message")
    
logger.Info("Informational message")
logger.Log(logm.LvlOk, "You should know it all went well")
    
logger.Log(logm.LvlNotice, "Notice this")
logger.Warning("Warrrrr arrrning")
    
logger.Error("Oh-ho an error over here")
logger.Log(logm.LvlPanic, "This is the end")

// you can specify any int as a log level
logger.Log(41, "Some higher log level")

Disable logging up to a certain level:

// only log Warnings and more important logs
logger.LogLevel = logm.LvlWarning 

// only log logs with level >= 41
logger.LogLevel = 41

Disable colored output:

logger.DisableColor = true

Example outputs

logm-whiteonblack logm-breeze logm-solarized logm-monokai

Customizing

Logm is a one file, about 140 lines, package. You can copy it into your project and customize the logger as you please :)

License

MIT

Documentation

Index

Constants

View Source
const (
	LvlVerbose = 0
	LvlInfo    = 1
	LvlOk      = 2
	LvlNotice  = 3
	LvlWarning = 4
	LvlError   = 5
	LvlPanic   = 6

	LvlMute = 100
)

Log Level constants used for log-level filtering and coloring

Variables

This section is empty.

Functions

This section is empty.

Types

type Logm

type Logm struct {

	// DisableColor specifies if log output in console should use colors
	DisableColor bool // = false

	/*
		Log level to be output. Verbose level (0) enables all, info level (1) enables info and more
		important, warning level (2) enables warning, error and higher level, etc.
	*/
	LogLevel int
	// contains filtered or unexported fields
}

Logm is an instance of the logger

func New

func New(logPrefix string) Logm

New instantiates a new logger with a given log prefix

func NewWithOutput

func NewWithOutput(out io.Writer, logPrefix string) Logm

NewWithOutput instantiates a new logger with a given output writer and log prefix

func (Logm) Error

func (l Logm) Error(message string)

Error logs an error message

func (Logm) Info

func (l Logm) Info(message string)

Info logs an info message

func (Logm) Log

func (l Logm) Log(logLevel int, logMessage string)

Log logs a message with given log level. Loglevel should be one of the Lvl* constants from this package.

func (Logm) Verbose

func (l Logm) Verbose(message string)

Verbose logs a verbose message

func (Logm) Warning

func (l Logm) Warning(message string)

Warning logs a warning message

Jump to

Keyboard shortcuts

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