log

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 0 Imported by: 33

README

Tiny logging API

This library provides a basic API to be integrated with any logging framework. It allows to use logging in your libraries without enforcing a particular logging framework.

Here is it:

// Logger interface
type Logger interface {

	// Debug logging: Every details
	Debug(event string, keyvals ...interface{})

	// Info logging: Core events
	Info(event string, keyvals ...interface{})

	// Warning logging: Anything out of the ordinary but non-life threatening
	Warn(event string, keyvals ...interface{})

	// Error logging: Major issue
	Error(event string, keyvals ...interface{})

	// Panic logging: We want to crash
	Panic(event string, keyvals ...interface{})

	// Context extending interface
	With(keyvals ...interface{}) Logger
}

It was designed for the ftpserverlib.

Compatible logging frameworks

slog
import (
	adapter "github.com/fclairamb/go-log/slog"
)

func main() {
	logger := adapter.NewWrap(slog.New())

	logger.Info("Hello world !")
}
go-kit/log
import (
	"os"

	gklog "github.com/go-kit/log"
	adapter "github.com/fclairamb/go-log/gokit"
)

func main() {
	gkLogger := gklog.NewLogfmtLogger(gklog.NewSyncWriter(os.Stdout))
	logger := adapter.NewWrap(gkLogger)

	logger.Info("Hello world !")
}
log15
import (
	"github.com/inconshreveable/log15"
	adapter "github.com/fclairamb/go-log/log15"
)

func main() {
	log15Logger := log15.New()
	logger := adapter.NewWrap(log15Logger)

	logger.Info("Hello world !")
}
zap
import (
	"go.uber.org/zap"
	adapter "github.com/fclairamb/go-log/zap"
)

func main() {
	innerLogger, _ := zap.NewProduction()
	logger := adapter.NewWrap(innerLogger.Sugar())

	logger.Info("Hello world !")
}
zerolog
import (
	zerolog "github.com/rs/zerolog/log"
	adapter "github.com/fclairamb/go-log/zerolog"
)

func main() {
	logger := adapter.NewWrap(&zerolog.Logger)

	logger.Info("Hello world !")
}

import (
	"github.com/sirupsen/logrus" //nolint: depguard
	adapter "github.com/fclairamb/go-log/logrus"
)

func main() {
	logrusLogger := logrus.New()
	logger := adapter.NewWrap(logrusLogger)

	logger.Info("Hello world !")
}

Documentation

Overview

Package log provides a simple interface to handle logging

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {

	// Debug logging: Every details
	Debug(event string, keyvals ...interface{})

	// Info logging: Core events
	Info(event string, keyvals ...interface{})

	// Warning logging: Anything out of the ordinary but non-life threatening
	Warn(event string, keyvals ...interface{})

	// Error logging: Major issue
	Error(event string, keyvals ...interface{})

	// Panic logging: We want to crash
	Panic(event string, keyvals ...interface{})

	// Context extending interface
	With(keyvals ...interface{}) Logger
}

Logger interface

Directories

Path Synopsis
Package gokit defines a simple implementation of the logging interface
Package gokit defines a simple implementation of the logging interface
Package level allows to do level filtering on go-log side
Package level allows to do level filtering on go-log side
Package log15 defines a simple implementation of the logging interface
Package log15 defines a simple implementation of the logging interface
Package logrus provides a logger based on logrus
Package logrus provides a logger based on logrus
Package logtest provides testing code for loggers
Package logtest provides testing code for loggers
Package noop provides a No-Operation logger
Package noop provides a No-Operation logger
Package slog defines a simple implementation of the logging interface
Package slog defines a simple implementation of the logging interface
Package testing provides an adapter for the go test testing logger
Package testing provides an adapter for the go test testing logger
Package zap defines a simple implementation of the logging interface
Package zap defines a simple implementation of the logging interface
Package zerolog defines a simple implementation of the logging interface
Package zerolog defines a simple implementation of the logging interface

Jump to

Keyboard shortcuts

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