A colored logger of golang
go get -u github.com/hiyali/logli
import (
log "github.com/hiyali/logli"
)
func main() {
log.Debug("This is a debug log actually")
log.FatalF("Damn, there is an error: %v", err) // followed an os.Exit(1)
}
Name | Color | Usage |
---|---|---|
Default | log.Print(msg string) |
|
PrintF | Default | log.Printf(format string, values ...interface{}) |
Debug | Cyan | Same as Print, like log.Debug(msg string) |
DebugF | Cyan | Same as PrintF, like log.DebugF(format string, values ...interface{}) |
Info | Green | Same to Debug |
InfoF | Green | Same to DebugF |
Warn | Yellow | Same to Debug |
WarnF | Yellow | Same to DebugF |
Error | Red | Same to Debug |
ErrorF | Red | Same to DebugF |
Fatal | Red | Same to Error and following os.Exit(1) |
FatalF | Red | Same to ErrorF and following os.Exit(1) |
Name | Color | Usage |
---|---|---|
CustomPrint | As you wish | log.CustomPrint(msg string, color color, typ int) |
CustomPrintNT | Like above | log.CustomPrintNT(msg string, color color, typ int) and no time will automatically print |
Colorize | You will choose | log.Colorize(msg string, color color) -> (result string) no any print here, but would return colorized result string |
Name | Usage |
---|---|
SetCustomTimeFormat | log.SetCustomTimeFormat("2006-01-02 15:04:05") |
Now | log.Now() -> (now string) return time string for now |
Option | Type | Default |
---|---|---|
TimeDisabled | bool | false |
ColorDisabled | bool | false |
TimeColor | color | Color.Default |
TimeFormat | time_format | TimeFormat.Default ("2006-01-02 15:04:05") |
How can I set config?
log.SetConfig(&log.Config{
TimeDisabled: true,
ColorDisabled: false,
...
})
How can I use these colors?
log.Color.Blue -> color
...
log.CustomPrint("Hey yo", log.Color.LightRed, log.TypeFace.Normal)
How can I get and use these time formats?
log.TimeFormat.UnixDate -> time_format
...
log.SetConfig(&log.Config{
TimeFormat: log.TimeFormat.Stamps,
...
})
Print all things it can do.
log.FullLook()
OR some of them
log.TakeLook()
log.Color.Print()
log.TimeFormat.Print()
Feel free
MIT
inspired By bclicn/color