Skip to content

guumaster/cligger

Repository files navigation

Tests Go Report Card Go Reference License Coverage

cligger

Simple CLI logger with colored symbols Includes fallbacks for Windows CMD which only supports a limited character set.

cligger output example

Install

$ go get github.com/guumaster/cligger

Usage

Basic example

package main

import (
  "fmt"
  log "github.com/guumaster/cligger"
)

func main() {
    log.Success("Finished successfully!")
    log.Error("Something broke")

    // On good OSes:  ✔ Finished successfully!
    //                ✖ Something broke

    // On Windows:    √ Finished successfully!
    //                × Something broke
}

Forcing colors

cligger will autodetect if its not in TTY mode and remove all colors. You can force color output with this example:

  	log.EnableColors()
    log.Success('Finished successfully!')

    // Terminal Output:   ✔ Finished successfully!
    // Redirected Output: ^[[1;32m✔^[[0m Finished successfully!

Create your own instance

cligger can work on Singleton mode or as an instance like this example:

    logger := cligger.NewLogger()
    logger.Success('Finished successfully!')

    // Output:  ✔ Finished successfully!

Change output writer

cligger defaults to os.Stdout but you can change it to any writer:

	content := bytes.NewBufferString("")

	logger := NewLoggerWithWriter(b)
	logger.Success("Finished successfully!")
	fmt.Println(content.String())

	// Output:  ✔ Finished successfully!

    // or write to file:
	ioutil.WriteFile("/tmp/log.out", content, 0644)

Related

Author(s)

If you like this tool and think is worth it, you can invite me a coffee:

paypal.me/guumaster ko-fi.com/guumaster

LICENSE

MIT license

About

Simple CLI logger with symbols and colors.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages