Categorygithub.com/njones/logger
repositorypackage
1.0.8
Repository: https://github.com/njones/logger.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

Build Status GoDoc Go Report Card

Logger

Logger is a go library that provides a full featured logger. It has structured logging and color capabilities.

See the GoDoc for more information.

Installation

go get github.com/njones/logger

Example of how to use the Logger

package main

import (
	"github.com/njones/logger"
	"github.com/njones/logger/color"
)

var log = logger.New()

func main() {
	x := "xyz"
	user, emails := "someone", []string{"somewhere", "overtherainbow"}

	log.Debug("Starting the main function ...")

	// does something
	log.Warnf("Doing %s ...", x)

	// uses a custom color
	log.With(WithColor(color.Blue)).Info("This is info, but displays in BLUE ...")
	log.Info("instead of info being GREEN.")

	// uses structured logging
	log.Debug("The thing occurred here.", logger.KV("user", user), logger.KV("email", emails))
	logf := log.Field("user", user)
	logf.Debug("The thing occurred here.", logger.KV("email", emails)) // mix and match

	// can supress
	log.Supress(logger.Trace)
	log.Error("Finished with main.") // will show up
	log.Trace("Finished with main.") // won't show up

	// conditional log, will only log if there is an error
	err := doSomething()
	log.OnErr(err).Fatal("will log and exit on error: %v", logger.OnErr{}) // logger.OnErr{} is a placeholder for err 
	// log.Panic("will panic") will panic
}

License

Logger is available under the MIT License.

Copyright (c) 2017-2020 Nika Jones [email protected] All Rights Reserved.