sugarkane

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 5 Imported by: 0

README

sugarkane

Opionated way to print information to a user AND log it to a file

Documentation

Overview

Package sugarkane tries to make it easy to show info to the user and the log with one call.

Example

https://blog.golang.org/examples

package main

import (
	"os"

	"github.com/bbkane/sugarkane"
	"go.uber.org/zap"

	lumberjack "gopkg.in/natefinch/lumberjack.v2"
)

func main() {
	// intialize a more useful lumberjack.Logger with:
	//   https://github.com/natefinch/lumberjack
	var lumberjackLogger *lumberjack.Logger = nil
	sk := sugarkane.NewSugarKane(lumberjackLogger, os.Stderr, os.Stdout, zap.DebugLevel, "v1.0.0")
	defer sk.Sync()
	sk.LogOnPanic()
	sk.Infow(
		"Now we're logging :)",
		"key", "value",
	)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Printw

func Printw(fp *os.File, msg string, keysAndValues ...interface{})

Printw formats and prints a msg and keys and values to a stream. Useful when you need to show info but you don't have a log

Types

type SugarKane

type SugarKane struct {
	// contains filtered or unexported fields
}

SugarKane is a very opinionated wrapper around a uber/zap sugared logger It's designed primarily to simultaneously print "pretty-enough" input for a user and useful enough info to a lumberjack logger It should really only be used with simple key/value pairs It's designed to be fairly easily swappable with the sugared logger

func NewSugarKane

func NewSugarKane(lumberjackLogger *lumberjack.Logger, errorStream *os.File, infoStream *os.File, lvl zapcore.LevelEnabler, appVersion string) *SugarKane

NewSugarKane creates a new SugarKane all ready to go

func (*SugarKane) Debugw

func (s *SugarKane) Debugw(msg string, keysAndValues ...interface{})

Debugw prints keys and values only to the log, not to the user

func (*SugarKane) Errorw

func (s *SugarKane) Errorw(msg string, keysAndValues ...interface{})

Errorw prints a message and keys and values with INFO level

func (*SugarKane) Infow

func (s *SugarKane) Infow(msg string, keysAndValues ...interface{})

Infow prints a message and keys and values with INFO level

func (*SugarKane) LogOnPanic

func (s *SugarKane) LogOnPanic()

LogOnPanic tries to log a panic. It should be called at the start of each goroutine. See panic and recover docs

func (*SugarKane) Sync

func (s *SugarKane) Sync() error

Sync syncs the underlying logger

Jump to

Keyboard shortcuts

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