cligger

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2020 License: MIT Imports: 5 Imported by: 2

README

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)

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

Documentation

Overview

nolint:goprintffuncname

nolint:goprintffuncname

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableColor

func DisableColor()

DisableColor strip colors from the singleton instance symbols

func EnableColor

func EnableColor()

EnableColor adds colors to the singleton instance symbols

func Error

func Error(format string, args ...interface{})

Error singleton method to log a string with an error symbol

func Errorf

func Errorf(format string, args ...interface{}) error

Errorf singleton method to get a wrapped error with an error symbol

func Fatal

func Fatal(format string, args ...interface{})

Fatal singleton method to log a message and exit the program

func Info

func Info(format string, args ...interface{})

Info singleton method to log a string with an info symbol

func SetWriter

func SetWriter(w io.Writer)

SetWriter set a new internal writer to the singleton instance

func Success

func Success(format string, args ...interface{})

Success singleton method to log a string with an success symbol

func Warning

func Warning(format string, args ...interface{})

Warning singleton method to log a string with an warning symbol

Types

type Log

type Log struct {
	// contains filtered or unexported fields
}

func (*Log) DisableColor

func (p *Log) DisableColor()

DisableColor strip TTY colors from symbols

func (*Log) EnableColor

func (p *Log) EnableColor()

EnableColor add TTY colors from symbols

func (Log) Error

func (p Log) Error(format string, args ...interface{})

Error logs a string with an error symbol

func (Log) Errorf

func (p Log) Errorf(format string, args ...interface{}) error

Errorf returns an error with a message containing an error symbol

func (Log) Fatal

func (p Log) Fatal(format string, args ...interface{})

Fatal logs an error containing an error symbol and exit the program

func (Log) Info

func (p Log) Info(format string, args ...interface{})

Info logs a string with an info symbol

func (Log) Success

func (p Log) Success(format string, args ...interface{})

Success logs a string with a success symbol

func (Log) Warning

func (p Log) Warning(format string, args ...interface{})

Warning logs a string with a warning symbol

type Logger

type Logger interface {
	Info(format string, args ...interface{})
	Success(pattern string, args ...interface{})
	Warning(pattern string, args ...interface{})
	Error(pattern string, args ...interface{})
	Errorf(pattern string, args ...interface{}) error
	Fatal(pattern string, args ...interface{})
	EnableColor()
	DisableColor()
}

func NewLogger

func NewLogger() Logger

NewLogger new logger with stdout writer

func NewLoggerWithWriter

func NewLoggerWithWriter(w io.Writer) Logger

NewLoggerWithWriter new logger with a specific writer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL