funkylog

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: MIT Imports: 8 Imported by: 0

README

funkylog

Simple logger for Go apps that doesn't take it's self too seriously.

  • Support for emoji's
  • Customize output text colours per log event level.
  • Set the time layout.

Sample output

Alt text

Prerequisites
  • Go version >= 1.15.2
Getting started
go get github.com/daiLlew/funkylog
Usage

Using the default setup:

import (
    log "github.com/daiLlew/funkylog"
)

...

// Set the log namespace
log.Init("my-app")

// Log an info message with some emojis.
log.Info("time for :beer:and :pizza:")

// Log a warning
log.Warn("something is not quite right")

// Log and error with arguments.
log.Err("this is an error! %+v", errors.New("encountered an unexpected error"))

Create your own styles and customize the output:

// Create a configuration to customize how the output should be formatted.
cfg := log.Configuration{
    Namespace: "my-app",
    TimeFmt:   time.RFC822,
    InfoStyle: log.NewStyle(color.FgHiCyan, ":unicorn_face:"),
    WarnStyle: log.NewStyle(color.FgHiBlue, ":tiger:"),
    ErrStyle:  log.NewStyle(color.FgHiMagenta, ":comet: "),
}

log.Customise(cfg)

log.Info("time for :beer:and :pizza:")
log.Warn("something is not quite right")
log.Err("this is an error! %+v", errors.New("encountered an unexpected error"))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Customise

func Customise(cfg Configuration)

func Err

func Err(msg string, args ...interface{})

func Info

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

func Init

func Init(name string)

func Warn

func Warn(msg string, args ...interface{})

Types

type Configuration

type Configuration struct {
	Namespace string
	TimeFmt   string
	InfoStyle Style
	WarnStyle Style
	ErrStyle  Style
}

type Style

type Style struct {
	Emoji  string
	Bold   *color.Color
	Italic *color.Color
	Plain  *color.Color
}

func NewStyle

func NewStyle(c color.Attribute, emojiStr string) Style

func (Style) Sprintf

func (s Style) Sprintf(msg string, args ...interface{}) string

func (Style) Write

func (s Style) Write(tw *tabwriter.Writer, msg string, args ...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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