log

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: MIT Imports: 7 Imported by: 9

README

Log

Installation

go get github.com/facily-tech/go-core/log

Usage

See examples documentation.

Documentation

Overview

Package log is a generated GoMock package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field is the way the parameters is received by logger.

func Any

func Any(key string, value interface{}) Field

Any receive any value to be add into logger.

func Error

func Error(value error) Field

Error handle errors to be given to looger function.

type Fields

type Fields struct {
	CTX    context.Context
	Fields []Field
}

Fields are the slice of fields that are handled internaly by logger function.

type Logger

type Logger interface {
	// Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any
	// fields accumulated on the logger.
	Error(ctx context.Context, msg string, fields ...Field)
	// Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any
	// fields accumulated on the logger.
	Debug(ctx context.Context, msg string, fields ...Field)
	// Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any
	// fields accumulated on the logger. The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
	// Defer aren't executed before exit! Use only in appropriated places like simple main() without defer.
	Fatal(ctx context.Context, msg string, fields ...Field)
	// Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields
	// accumulated on the logger.
	Info(ctx context.Context, msg string, fields ...Field)
	// Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields
	// accumulated on the logger. The logger then panics, even if logging at PanicLevel is disabled.
	Panic(ctx context.Context, msg string, fields ...Field)
	// Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields
	// accumulated on the logger.
	Warn(ctx context.Context, msg string, fields ...Field)
}

Logger defines a common contract we should follow for each new log provider.

type MockLogger

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

MockLogger is a mock of Logger interface.

func NewMockLogger

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance.

func (*MockLogger) Debug

func (m *MockLogger) Debug(arg0 context.Context, arg1 string, arg2 ...Field)

Debug mocks base method.

func (*MockLogger) EXPECT

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockLogger) Error

func (m *MockLogger) Error(arg0 context.Context, arg1 string, arg2 ...Field)

Error mocks base method.

func (*MockLogger) Fatal

func (m *MockLogger) Fatal(arg0 context.Context, arg1 string, arg2 ...Field)

Fatal mocks base method.

func (*MockLogger) Info

func (m *MockLogger) Info(arg0 context.Context, arg1 string, arg2 ...Field)

Info mocks base method.

func (*MockLogger) Panic

func (m *MockLogger) Panic(arg0 context.Context, arg1 string, arg2 ...Field)

Panic mocks base method.

func (*MockLogger) Warn

func (m *MockLogger) Warn(arg0 context.Context, arg1 string, arg2 ...Field)

Warn mocks base method.

type MockLoggerMockRecorder

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

MockLoggerMockRecorder is the mock recorder for MockLogger.

func (*MockLoggerMockRecorder) Debug

func (mr *MockLoggerMockRecorder) Debug(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

Debug indicates an expected call of Debug.

func (*MockLoggerMockRecorder) Error

func (mr *MockLoggerMockRecorder) Error(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

Error indicates an expected call of Error.

func (*MockLoggerMockRecorder) Fatal

func (mr *MockLoggerMockRecorder) Fatal(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

Fatal indicates an expected call of Fatal.

func (*MockLoggerMockRecorder) Info

func (mr *MockLoggerMockRecorder) Info(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

Info indicates an expected call of Info.

func (*MockLoggerMockRecorder) Panic

func (mr *MockLoggerMockRecorder) Panic(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

Panic indicates an expected call of Panic.

func (*MockLoggerMockRecorder) Warn

func (mr *MockLoggerMockRecorder) Warn(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call

Warn indicates an expected call of Warn.

type Zap

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

Zap wraps a zap.Logger and implements Logger inteface.

func NewLoggerZap

func NewLoggerZap(config ZapConfig) (*Zap, error)

NewLoggerZap implements Logger using uber zap structured log package.

Example
log, err := NewLoggerZap(ZapConfig{
	Version:           "v0.1.0",
	DisableStackTrace: false,
})
if err != nil {
	// panic should not be used outside func main
	// but it is not possible to return on it tests
	panic(err)
}

ctx := context.Background()
log.Info(ctx, "new log created successfully")
Example (WithTracing)
version := "v0.1.0"

// If is there already a tracer instance of telemetry you should use it
// this imsplementation exists only for example how to add a log tracer on it
tracer := telemetry.NewDataDog(telemetry.DataDogConfig{
	Env:     "Local",   // environment one of: local, development, homolog, production.
	Service: "Service", // application service name, it should be the same of it repository ( Github, Bitbucket, etc ).
	Version: version,   // Code Version, if there is no version control, then use Git Commit Hash instead.
})

log, err := NewLoggerZap(ZapConfig{
	Version:           version,
	DisableStackTrace: false,
	Tracer:            tracer,
})
if err != nil {
	// panic should not be used outside func main
	// but it is not possible to return on it tests
	panic(err)
}

ctx := context.Background()
log.Info(ctx, "new log created successfully")

func (*Zap) Debug

func (z *Zap) Debug(ctx context.Context, msg string, fields ...Field)

Debug will write a log with level debug.

func (*Zap) Error

func (z *Zap) Error(ctx context.Context, msg string, fields ...Field)

Error will write a log with level error.

func (*Zap) Fatal

func (z *Zap) Fatal(ctx context.Context, msg string, fields ...Field)

Fatal will write a log with level fatal.

func (*Zap) Info

func (z *Zap) Info(ctx context.Context, msg string, fields ...Field)

Info will write a log with level info.

func (*Zap) Panic

func (z *Zap) Panic(ctx context.Context, msg string, fields ...Field)

Panic will write a log with level panic.

func (*Zap) Warn

func (z *Zap) Warn(ctx context.Context, msg string, fields ...Field)

Warn will write a log with level warn.

type ZapConfig

type ZapConfig struct {
	Version           string
	DisableStackTrace bool
	Tracer            telemetry.Tracer
}

ZapConfig handle the config information that will be passed to zap.

Jump to

Keyboard shortcuts

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