Skip to content

MrMarble/tasklog

Repository files navigation

TaskLog :ballot_box_with_check:

Go Report Card Go Reference GitHub License Test

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.

Installation

go get -u github.com/mrmarble/tasklog

Getting Started

Simple Logging Example

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

Logging additional information

You can also log additional information by using the Printmethods

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.

Custom Logger

You can customize the logger by using the corresponding Setmethods.

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

Contributing

I welcome any contributions. Just create a PR or an issue.

About

Task logging library for Golang

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Languages