l

package module
v0.0.0-...-5eb3217 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: MIT Imports: 15 Imported by: 0

README

Golang Pretty Logger (Warning! Not Maintened.)

Custom go logger for pretty print, log, debug, warn, error with colours and levels.

Usage

Install
go get github.com/happierall/l
Usage
import "github.com/happierall/l"

func main() {
   l.Log(10 + 5)
   l.Print("Without datetime and code line")
   
   people := &People{"Name"}
   l.Debug(people)

   l.Warn("Function is depreceted")
   l.Error("User is not defined")
   l.Logf("%d ms", 10)
   l.Printf("Request %s ms", l.Colorize("53", l.Green))
}

type People struct {
    Name string
}

Terminal output: Output struct and int

Custom logger
var log = l.New()
log.Prefix = log.Colorize("[APP] ", l.Blue)
log.Level = l.LevelDebug // default
log.DisabledInfo = true  // without date and code line

log.Debug("Message without date and line with prefix")
Production mode

(without colors)

l.Default.Production = true
Subscribe on logs
l.Default.Subscribe(func(text string, lvl l.Level) {
	fmt.Println("New log", text, lvl.String())
})
Based on

y0ssar1an/q

License

MIT

Documentation

Index

Constants

View Source
const (
	// ANSI color escape codes
	Bold        color = "\033[1m"
	Yellow      color = "\033[33m"
	Cyan        color = "\033[36m"
	Gray        color = "\033[90m"
	Red         color = "\033[31m"
	Blue        color = "\033[34m"
	Pink        color = "\033[35m"
	Green       color = "\033[32m"
	LightRed    color = "\033[91m"
	LightGreen  color = "\033[92m"
	LightYellow color = "\033[93m"
	LightBlue   color = "\033[94m"
	LightPink   color = "\033[95m"
	LightCyan   color = "\033[96m"
	White       color = "\033[97m"
	Black       color = "\033[30m"
)

Variables

View Source
var Default = New()

Default instance (global)

Functions

func Colorize

func Colorize(text string, c color) string

Colorize output from default logger

func Crit

func Crit(v ...interface{})

Crit from default instance

func Critf

func Critf(format string, v ...interface{})

Critf from default instance

func Debug

func Debug(v ...interface{})

Debug from default instance

func Debugf

func Debugf(format string, v ...interface{})

Debugf from default instance

func Error

func Error(v ...interface{})

Error from default instance

func Errorf

func Errorf(format string, v ...interface{})

Errorf from default instance

func Log

func Log(v ...interface{})

Log from default instance

func Logf

func Logf(format string, v ...interface{})

Logf from default instance

func Print

func Print(v ...interface{})

Print from default instance

func Printf

func Printf(format string, v ...interface{})

Printf from default instance

func Warn

func Warn(v ...interface{})

Warn from default instance

func Warnf

func Warnf(format string, v ...interface{})

Warnf from default instance

Types

type Level

type Level int

Level log

const (
	// LevelCrit show error and os.Exit(1)
	LevelCrit Level = iota
	// LevelError Error conditions(Ex: An application has exceeded its file storage limit and attempts to write are failing)
	LevelError
	// LevelWarning May indicate that an error will occur if action is not taken (Ex: A non-root file system has only 2GB remaining)
	LevelWarning
	// LevelInfo Normal operation events that require no action (Ex: An application has started, paused or ended successfully.
	LevelInfo
	// LevelDebug Information useful to developers for debugging an application
	LevelDebug
)

func (Level) Color

func (l Level) Color() color

func (Level) String

func (l Level) String() string

type Logger

type Logger struct {
	Prefix       string
	DisabledInfo bool
	Production   bool
	Depth        int
	Level        Level
	// contains filtered or unexported fields
}

Logger instance

func New

func New() *Logger

New Logger

func (*Logger) Colorize

func (t *Logger) Colorize(text string, c color) string

Colorize output

func (*Logger) Crit

func (t *Logger) Crit(v ...interface{})

Crit log and os.Exit(1)

func (*Logger) Critf

func (t *Logger) Critf(format string, v ...interface{})

Critf format log and os.Exit(1)

func (*Logger) Debug

func (t *Logger) Debug(v ...interface{})

Debug with date and file info

func (*Logger) Debugf

func (t *Logger) Debugf(format string, v ...interface{})

Debugf format with date and file info

func (*Logger) Error

func (t *Logger) Error(v ...interface{})

Error log

func (*Logger) Errorf

func (t *Logger) Errorf(format string, v ...interface{})

Errorf format log

func (*Logger) Log

func (t *Logger) Log(v ...interface{})

Log with date and file info

func (*Logger) Logf

func (t *Logger) Logf(format string, v ...interface{})

Logf format with date and file info

func (*Logger) Print

func (t *Logger) Print(v ...interface{})

Print without date and file info

func (*Logger) Printf

func (t *Logger) Printf(format string, v ...interface{})

Printf format without date and file info

func (*Logger) Subscribe

func (t *Logger) Subscribe(handler func(text string, lvl Level))

Subscribe on every log

func (*Logger) Warn

func (t *Logger) Warn(v ...interface{})

Warn with date and file info

func (*Logger) Warnf

func (t *Logger) Warnf(format string, v ...interface{})

Warnf format with date and file info

Jump to

Keyboard shortcuts

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