example

package module
v0.0.0-...-8a9c8d7 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2020 License: MIT Imports: 1 Imported by: 0

README

Logur Examples

GoDoc

This package contains various usage and implementation examples for Logur:

It also contains a custom example logger you might want to use in your application. Feel free to copy and customize it to your needs.

For a real application example, check out sagikazarmark/modern-go-application:

Documentation

Overview

Example (Bugsnag)
logger := logur.NoopLogger{} // choose an actual implementation

bugsnag.New(bugsnag.Configuration{
	Logger: logur.NewErrorPrintLogger(logger),
})
Output:

Example (GoKitLog)
logger := logur.NoopLogger{} // choose an actual implementation

log.With(kitintegration.New(logger), "key", "value")
Output:

Example (GrpcLog)
logger := logur.NoopLogger{} // choose an actual implementation

grpclog.SetLoggerV2(grpcintegration.New(logger))
Output:

Example (MysqlDriver)
logger := logur.NoopLogger{} // choose an actual implementation

_ = mysql.SetLogger(logur.NewErrorPrintLogger(logger))
Output:

Example (Rollbar)
logger := logur.NoopLogger{} // choose an actual implementation
clientLogger := logur.NewErrorPrintLogger(logger)

rollbar.SetLogger(clientLogger)
// OR
notifier := rollbar.New("token", "environment", "version", "host", "root")
notifier.SetLogger(clientLogger)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger 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{})

	// WithFields annotates a logger with some context and it as a new instance.
	WithFields(fields map[string]interface{}) Logger
}

Logger is the fundamental interface for all log operations.

type LoggerAdapter

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

LoggerAdapter wraps a logur logger and exposes it under a custom interface.

func NewLoggerAdapter

func NewLoggerAdapter(logger logur.Logger) *LoggerAdapter

NewLoggerAdapter returns a new Logger instance.

func (*LoggerAdapter) Debug

func (l *LoggerAdapter) Debug(msg string, fields ...map[string]interface{})

Debug logs a debug event.

func (*LoggerAdapter) Error

func (l *LoggerAdapter) Error(msg string, fields ...map[string]interface{})

Error logs an error event.

func (*LoggerAdapter) Info

func (l *LoggerAdapter) Info(msg string, fields ...map[string]interface{})

Info logs an info event.

func (*LoggerAdapter) Trace

func (l *LoggerAdapter) Trace(msg string, fields ...map[string]interface{})

Trace logs a trace event.

func (*LoggerAdapter) Warn

func (l *LoggerAdapter) Warn(msg string, fields ...map[string]interface{})

Warn logs a warning event.

func (*LoggerAdapter) WithFields

func (l *LoggerAdapter) WithFields(fields map[string]interface{}) Logger

WithFields annotates a logger with some context and it as a new instance.

Jump to

Keyboard shortcuts

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