Skip to content

FurqanSoftware/pog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pog

Go Reference CI

Pog is a simple logger for Go with a status indicator.

We use Pog in Toph Printd.

Usage

import (
	"github.com/FurqanSoftware/pog"
	"github.com/fatih/color"
)

type pogStatus struct {
	icon  byte
	text  string
	color *color.Color
	throb bool
}

func (s pogStatus) Icon() byte          { return s.icon }
func (s pogStatus) Text() string        { return s.text }
func (s pogStatus) Color() *color.Color { return s.color }
func (s pogStatus) Throb() bool         { return s.throb }

var (
	statusReady    = pogStatus{'~', "Ready", color.New(color.FgGreen), true}
	statusPrinting = pogStatus{'~', "Printing", color.New(color.FgBlue), false}
	statusOffline  = pogStatus{'!', "Offline", color.New(color.FgRed), false}
)
log.SetPrefix("\033[2K\r")
log.SetFlags(log.Ldate | log.Ltime)

pog.InitDefault()

pog.Info("I am ready.")
pog.SetStatus(statusReady)
2023/10/18 11:59:11 [i] I am ready.
                    [~] Ready
pog.Info("Got a print.")
pog.SetStatus(statusPrinting)
pog.Warn("That's a lot of words.")
2023/10/18 11:59:11 [i] I am ready.
2023/10/18 11:59:19 [i] Got a print.
2023/10/18 11:59:19 [w] That's a lot of words.
                    [~] Printing
pog.Error("Lost connection.")
pog.SetStatus(statusOffline)
2023/10/18 11:59:11 [i] I am ready.
2023/10/18 11:59:19 [i] Got a print.
2023/10/18 11:59:19 [w] That's a lot of words.
2023/10/18 11:59:57 [E] Lost connection.
                    [!] Offline

Log Levels

Level Indicator Variants
Debug [d] Debug, Debugln, Debugf
Info [i] Info, Infoln, Infof
Warn [w] Warn, Warnln, Warnf
Error [E] Error, Errorln, Errorf
Fatal [E] Fatal, Fatalln, Fatalf

Fatal functions log at the Error level and then exit, running any registered exit hooks.

Exit Hooks

Register functions to run before a Fatal exit:

pog.AddExitHook(func() {
	// Clean up resources.
})

About

A simple logger for Go with a status indicator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages