TaskLog is a task-based logger for Go (golang) with a simple API interface.
It's intended to be used by humans, as it uses ansi escape codes to format the output, making it easy to read in a terminal.
go get -u github.com/mrmarble/tasklog
For simple logging, import the global logger package github.com/mrmarble/tasklog/log
package main
import "github.com/mrmarble/tasklog/log"
func main() {
log.Task("Doing some work")
log.Task("Another task")
log.Skip("some reason")
}
// Output: [✓] Doing some work
// [→] Another task (some reason)
Note: By default log writes to os.Stderr
You can also log additional information by using the Print
methods
package main
import "github.com/mrmarble/tasklog/log"
func main() {
log.Task("Doing some work")
log.Print("This is some additional information")
}
// Output: [✓] Doing some work
// This is some additional information
By default, the additional information is deleted when a new task is started. You can change this behavior by using a custom logger.
You can customize the logger by using the corresponding Set
methods.
package main
import (
"os"
"github.com/charmbracelet/x/ansi"
"github.com/mrmarble/tasklog"
)
func main() {
log := tasklog.New(os.Stdout)
log.SetPersistent(true) // Keep the additional information when a new task is started
log.SetProgressColor(ansi.HexColor("#88AAFF")). // Supports any color implementing color.Color interface
log.Task("Doing some work")
}
// Output: [ ] Doing some work
I welcome any contributions. Just create a PR or an issue.