Skip to content

A small and simple go package that provides a few logging functions to log info/errors to aid in development

License

Notifications You must be signed in to change notification settings

jesse-rb/slogger-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slogger: simple go logger

This is a small go package that provides a few simple logging functions to aid in development. This package allows you to register a new logger very similar to how you would a standard go log.Logger, with the added ability to pass paremeters to configure a log color (using ANSI color codes) and some log prefixese.

pkg.go.dev docs page

install in project

Using go modules, from your project directory you can run:

go get github.com/jesse-rb/slogger-go 

example usage

package main

import (
	slogger "github.com/jesse-rb/slogger-go"
    log
    os
)

func main() {
    // Declare some loggers
    infoLogger := slogger.New(os.Stdout, slogger.ANSIBlue, "info", log.Lshortfile+log.Ldate);
    errorLogger := slogger.New(os.Stderr, slogger.ANSIRed, "error", log.Lshortfile+log.Ldate);

    // Log some things
    infoLogger.Log("main", "Something worth noting happened", 2+4)
    errorLogger.Log("main", "Some horrible error happened", []int{3, 5, 7})
}

preview logs

preview image A

References

Referenced 3 bit 8 colours from Haoyi's Programming Blog as most terminals should supprot this

const (
    ANSIReset    = "\u001b[0m"
    ANSIRed      = "\u001b[31m"
    ANSIBlue     = "\u001b[34m"
    ANSIBlack    = "\u001b[30m"
    ANSIGreen    = "\u001b[32m"
    ANSIYellow   = "\u001b[33m"
    ANSIMagenta  = "\u001b[35m"
    ANSICyan     = "\u001b[36m"
    ANSIWhite    = "\u001b[37m"
)

About

A small and simple go package that provides a few logging functions to log info/errors to aid in development

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages