colorlog

package module
v0.0.0-...-c17db98 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: MIT Imports: 3 Imported by: 6

README

colorlog

Simple fancy logging package for Go. Built for usage in simple personal projects

This

  • Is a simple logging built upon basic Golang packages.
  • Prints logging statements with a bit of color and zing.

This is not

  • Performant logging library for performant applications.
  • To be used for critical applications where logging is a debugging/auditing requirement.

Usage

This library simply has 7 simple functions. Which follow the familiar Printf format.

  • LogSuccess: Prints green good stuff
  • LogError: Prints red bad stuff
  • LogInfo: Prints neutral info stuff
  • LogFatal: Prints the given message in red and exits! Use only for very fatal errors.

LogSuccess, LogError and LogInfo has their own Fancy counterpart, which prints the same with basic ASCII symbols.

colorlog.LogSuccess("Everything is %s", "right")
colorlog.LogError("Everything is %s", "bad")
colorlog.LogInfo("Everything is %s", "okay")
colorlog.LogFatal("Everything is %s", "fucked")

colorlog.LogSuccessFancy("Everything is %s", "right")
colorlog.LogErrorFancy("Everything is %s", "bad")
colorlog.LogInfoFancy("Everything is %s", "okay")

If needing a dependency injection method. We also provide a ColorLogger interface which requires the same 7 functions. We provide a DefaultColorLogger type for actuall logging. The ColorLogger interface can be mocked for testing purposes.

logger := &colorlog.DefaultColorLogger{}

logger.LogSuccess("Everything is %s", "right")
logger.LogError("Everything is %s", "bad")
logger.LogInfo("Everything is %s", "okay")
logger.LogFatal("Everything is %s", "fucked")

logger.LogSuccessFancy("Everything is %s", "right")
logger.LogErrorFancy("Everything is %s", "bad")
logger.LogInfoFancy("Everything is %s", "okay")


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogError

func LogError(format string, v ...interface{})

Log when something goes wrong Prints using a red color

func LogErrorFancy

func LogErrorFancy(format string, v ...interface{})

Log something negative Prints in red with a ASCII X (`x`)

func LogFatal

func LogFatal(format string, v ...interface{})

Log when something does very wrong Prints using red color Additionally exits from the application using `os.Exit`

func LogInfo

func LogInfo(format string, v ...interface{})

Log when communicating some info Prints using a yellow color

func LogInfoFancy

func LogInfoFancy(format string, v ...interface{})

Log something informative Prints in yello in ASCII plug (`+`)

func LogSuccess

func LogSuccess(format string, v ...interface{})

Log when something goes right Prints using green color

func LogSuccessFancy

func LogSuccessFancy(format string, v ...interface{})

Log something positive Prints in green with a ASCII tick (`✓`)

Types

type ColorLogger

type ColorLogger interface {
	LogSuccess(string, ...interface{})
	LogError(string, ...interface{})
	LogInfo(string, ...interface{})
	LogFatal(string, ...interface{})

	LogSuccessFancy(string, ...interface{})
	LogErrorFancy(string, ...interface{})
	LogInfoFancy(string, ...interface{})
}

ColorLogger interface for dependency injection purposes. Useful for mocking with custom type.

type DefaultColorLogger

type DefaultColorLogger struct {
}

Empty struct for implementing the ColorLogger interface.

func (*DefaultColorLogger) LogError

func (d *DefaultColorLogger) LogError(format string, v ...interface{})

func (*DefaultColorLogger) LogErrorFancy

func (d *DefaultColorLogger) LogErrorFancy(format string, v ...interface{})

func (*DefaultColorLogger) LogFatal

func (d *DefaultColorLogger) LogFatal(format string, v ...interface{})

func (*DefaultColorLogger) LogInfo

func (d *DefaultColorLogger) LogInfo(format string, v ...interface{})

func (*DefaultColorLogger) LogInfoFancy

func (d *DefaultColorLogger) LogInfoFancy(format string, v ...interface{})

func (*DefaultColorLogger) LogSuccess

func (d *DefaultColorLogger) LogSuccess(format string, v ...interface{})

func (*DefaultColorLogger) LogSuccessFancy

func (d *DefaultColorLogger) LogSuccessFancy(format string, v ...interface{})

Jump to

Keyboard shortcuts

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