verbose

package module
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: MIT Imports: 2 Imported by: 9

README

verbose go package

verbose package generates formatted output only when verbose mode is turned on.

Go Reference

Every formatted output starts with a colored message type:

  • INFO: >>info: in cyan
  • WARNING: >>warn: in orange
  • ALERT: >>alert: in red
  • TRACK: >>track: in green
  • DEBUG: >>debug: in yellow

Very easy to use like fmt.Println, fmt.Printf... but with verbose.Println, verbose.Printf...

Licence

MIT License

Documentation

Overview

verbose package generates formatted output only when verbose mode is turned on.

MessageType defines the header of the message and its color

  • INFO: `>>info:` in cyan before the message
  • TRACKER: `>>tracker:` in green before the messsage
  • WARNING: `>>warning:` in orange before the messsage
  • ALERT: `>>alert:` in red before the messsage

Usage

verbose.Println(verbose.INFO, "everything is ok")
verbose.Printf(verbose.WARNING, "value should be greater than %v", value)

Index

Constants

This section is empty.

Variables

View Source
var IsDebugging bool = false
View Source
var IsOn bool = false

Set this flag to generate verbose output

Functions

func Assert

func Assert(ok bool, format string, params ...interface{})

Assert panics with a formated message if not ok, whatever IsOn and IsDebugging.

func Debug

func Debug(format string, params ...interface{})

Debug prints a formated string to the standard stream only if versbode IsDebugging is true, otherwise does nothing.

func Error

func Error(context string, err error) error

Error formats and calls Output to print to the standard stream, like Println with the messageType ALERT and only if err is not nil.

func Print

func Print(msgtype MessageType, params ...interface{})

Print formats and calls Output to print to the standard stream. Arguments are handled in the manner of fmt.Print.

func Printf

func Printf(msgtype MessageType, format string, params ...interface{})

Printf formats and calls Output to print to the standard stream. Arguments are handled in the manner of fmt.Printf.

func PrintfIf

func PrintfIf(ok bool, msgtype MessageType, format string, params ...interface{})

PrintfIf formats and calls Output to print to the standard stream. Print out only if verbose IsOn and ok is true. Arguments are handled in the manner of fmt.Printf.

func Println

func Println(msgtype MessageType, params ...interface{})

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended.

func Track

func Track(start time.Time, format string, params ...interface{})

Track generate output a time tracker and a message if verbose IsOn, otherwise does nothing.

Types

type MessageType

type MessageType int

Type of verbose message, defines the header of the message and its color

  • INFO: `>>info:` in cyan before the message
  • TRACK: `>>track:` in red before the messsage
  • WARNING: `>>warn:` in orange before the messsage
  • ALERT: `>>alert:` in red before the messsage
const (
	INFO    MessageType = 0 // will output ">>info:" in cyan before the messsage
	WARNING MessageType = 1 // will output ">>warning:" in orange before the messsage
	ALERT   MessageType = 2 // will output ">>alert:" in red before the messsage
	TRACK   MessageType = 3 // will output ">>track: {timestamp}" in green before the messsage
	DEBUG   MessageType = 4 // will output ">>debug: in yellow before the messsage
)

Jump to

Keyboard shortcuts

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