testinglogur

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 4 Imported by: 3

README

testinglogur

GoDoc

Install:

go get github.com/muir/testinglogur

There is a proliferation of Go logging packages. Most are pretty similar and just provide ways to manage text logs with levels, colors, and various output adaptors. Many allow tagging and inheriting of tags.

There are a few logging packages that allow rich data to be logged.

Choosing a logger is a touch decision for a project. But, what if your project is not a app, but rather an open-source library? Which logger do you use then? The README for logur has an answer. Use the following:

type MyLogger interface {
	Trace(msg string, fields ...map[string]interface{})
	Debug(msg string, fields ...map[string]interface{})
	Info(msg string, fields ...map[string]interface{})
	Warn(msg string, fields ...map[string]interface{})
	Error(msg string, fields ...map[string]interface{})
}

There are adaptors to make a number of the more interesting logging packages conform to this interface so using this interface for your library still gives people who use your library the freedom to choose the logger they like best.

So that still leaves one gap: how do you test your library?

This package, testinglogur is the answer:

import "github.com/muir/testinglogur"

func TestMyTest(t *testing.T) {
	log := testinglogur.Get(t)
	TestYourLibrary(log)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MyLogger

type MyLogger interface {
	Trace(msg string, fields ...map[string]interface{})
	Debug(msg string, fields ...map[string]interface{})
	Info(msg string, fields ...map[string]interface{})
	Warn(msg string, fields ...map[string]interface{})
	Error(msg string, fields ...map[string]interface{})
}

This is the logger interface suggested by https://github.com/logur/logur

func Get

func Get(t T) MyLogger

Get returns a logger that matches the interface proposed by log

type T

type T interface {
	Log(...interface{})
}

Jump to

Keyboard shortcuts

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