README ¶
Golang Pretty Logger (Warning! Not Maintened.)
Custom go logger for pretty print, log, debug, warn, error with colours and levels.
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:
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
License
Documentation ¶
Index ¶
- Constants
- Variables
- func Colorize(text string, c color) string
- func Crit(v ...interface{})
- func Critf(format string, v ...interface{})
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Log(v ...interface{})
- func Logf(format string, v ...interface{})
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Warn(v ...interface{})
- func Warnf(format string, v ...interface{})
- type Level
- type Logger
- func (t *Logger) Colorize(text string, c color) string
- func (t *Logger) Crit(v ...interface{})
- func (t *Logger) Critf(format string, v ...interface{})
- func (t *Logger) Debug(v ...interface{})
- func (t *Logger) Debugf(format string, v ...interface{})
- func (t *Logger) Error(v ...interface{})
- func (t *Logger) Errorf(format string, v ...interface{})
- func (t *Logger) Log(v ...interface{})
- func (t *Logger) Logf(format string, v ...interface{})
- func (t *Logger) Print(v ...interface{})
- func (t *Logger) Printf(format string, v ...interface{})
- func (t *Logger) Subscribe(handler func(text string, lvl Level))
- func (t *Logger) Warn(v ...interface{})
- func (t *Logger) Warnf(format string, v ...interface{})
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 ¶
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 )
type Logger ¶
type Logger struct { Prefix string DisabledInfo bool Production bool Depth int Level Level // contains filtered or unexported fields }
Logger instance
Click to show internal directories.
Click to hide internal directories.