Documentation
¶
Overview ¶
Package tasklog provides a simple task logging system with support for task management, error handling, and output formatting.
A global Logger can be use for simple logging:
import "github.com/mrmarble/tasklog/log" log.Task("hello world") log.Done() // Output: [✓] hello world
NOTE: To import the global logger, import the "log" subpackage "github.com/mrmarble/tasklog/log".
Index ¶
- type TaskLogger
- func (t *TaskLogger) Clear()
- func (t *TaskLogger) Done()
- func (t *TaskLogger) Error(e error)
- func (t *TaskLogger) Print(args ...any)
- func (t *TaskLogger) Printf(format string, args ...any)
- func (t *TaskLogger) Println(args ...any)
- func (t *TaskLogger) SetErrorColor(c color.Color)
- func (t *TaskLogger) SetPersistError(persistError bool)
- func (t *TaskLogger) SetPersistent(persistent bool)
- func (t *TaskLogger) SetProgressColor(c color.Color)
- func (t *TaskLogger) SetSkipColor(c color.Color)
- func (t *TaskLogger) SetSuccessColor(c color.Color)
- func (t *TaskLogger) Skip(reason ...string)
- func (t *TaskLogger) Task(name string)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TaskLogger ¶
type TaskLogger struct {
// contains filtered or unexported fields
}
A TaskLogger represents an active logging object that can manage tasks, errors, and output formatting.
func New ¶
func New(w io.Writer) *TaskLogger
New creates a new TaskLogger instance with the specified output writer.
Example ¶
package main import ( "os" "github.com/mrmarble/tasklog" ) func main() { log := tasklog.New(os.Stdout) log.Task("Example Task") }
Output: �[1;30m [ ] Example Task�[m
func (*TaskLogger) Error ¶
func (t *TaskLogger) Error(e error)
Error marks the current task as failed with an error.
func (*TaskLogger) Print ¶
func (t *TaskLogger) Print(args ...any)
Print prints a message to the logger without a newline, prepending a tab for alignment.
func (*TaskLogger) Printf ¶
func (t *TaskLogger) Printf(format string, args ...any)
Printf formats and prints a message to the logger, prepending a tab for alignment.
func (*TaskLogger) Println ¶
func (t *TaskLogger) Println(args ...any)
Println prints a message to the logger with a newline, prepending a tab for alignment.
func (*TaskLogger) SetErrorColor ¶
func (t *TaskLogger) SetErrorColor(c color.Color)
SetErrorColor sets the color for error messages.
func (*TaskLogger) SetPersistError ¶
func (t *TaskLogger) SetPersistError(persistError bool)
SetPersistError sets whether the error should remain in context after completion.
func (*TaskLogger) SetPersistent ¶
func (t *TaskLogger) SetPersistent(persistent bool)
SetPersistent sets whether the task should remain in context after completion.
func (*TaskLogger) SetProgressColor ¶
func (t *TaskLogger) SetProgressColor(c color.Color)
SetProgressColor sets the color for the active task.
func (*TaskLogger) SetSkipColor ¶
func (t *TaskLogger) SetSkipColor(c color.Color)
SetSkipColor sets the color for skipped tasks.
Example ¶
package main import ( "os" "github.com/charmbracelet/x/ansi" "github.com/mrmarble/tasklog" ) func main() { log := tasklog.New(os.Stdout) log.SetSkipColor(ansi.BrightCyan) log.Task("Example Task") log.Skip() }
Output: �[1;30m [ ] Example Task�[m �[2K�[A�[1G�[2K�[1;96m [→] Example Task�[m
func (*TaskLogger) SetSuccessColor ¶
func (t *TaskLogger) SetSuccessColor(c color.Color)
SetSuccessColor sets the color for success messages.
Example ¶
package main import ( "image/color" "os" "github.com/mrmarble/tasklog" ) func main() { log := tasklog.New(os.Stdout) log.SetSuccessColor(color.RGBA{R: 0, G: 255, B: 0, A: 255}) log.Task("Example Task") log.Done() }
Output: �[1;30m [ ] Example Task�[m �[2K�[A�[1G�[2K�[1;38;2;0;255;0m [✓] Example Task�[m
func (*TaskLogger) Skip ¶
func (t *TaskLogger) Skip(reason ...string)
Skip marks the current task as skipped with an optional reason.
func (*TaskLogger) Task ¶
func (t *TaskLogger) Task(name string)
Task creates a new task with the given name.