Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

secondtruth/go-logger

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Go Logger interface with implementations

This library provides a common interface for logging in Go. It also provides an implementation of the interface for slog, which is part of the standard library.

Coming soon in independent repositories: Implementations for two other popular log libraries: Logrus and zap.

Why is this interface useful?

When we create libraries in general we shouldn't be logging but at times we do have to log, debug what the library is doing or trace the log.

We cannot implement a library with one log library and expect other applications to use the same log library. Here is where this interface comes in. It allows others to change the log library at any time without changing the code.

Installation

To install go-logger, use the following command:

go get -u github.com/secondtruth/go-logger

Quick Start

Example for slog

package main

import (
	"os"
	"log/slog"

	"github.com/secondtruth/go-logger/logger"
)

func main() {
	slogHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
		Level: slog.LevelDebug,
	})
	slogLog := slog.New(slogHandler)
	log, _ := logger.NewSlogLogger(slogLog)
	
	log.WithFields(logger.Fields{
		"foo": "bar",
	}).Info("message")
}

About

๐Ÿ“– Common interface for logging facilities in Go

Topics

Resources

Stars

Watchers

Forks

Releases

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.