logger

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: MIT Imports: 2 Imported by: 2

README

Logger

Logger is a package that prints messages of information, warnings, errors, etc. We use this package as a resource to obtain logs of things that are happening and that information helps us debug and know where in the code an error is occurring. This package is totally independent and the information it prints depends on what we pass to it.

Go

This package makes use of the external package zap.

Getting Started

Go is required in version 1.21 or higher.

Install

go get -u gitlab.com/prettytechnical-tools/logger

Features
  • Lightweight, less than 200 lines of code.
  • Easy to use.
Basic use
package main

import (
	"gitlab.com/prettytechnical-tools/logger"
	"os"
)

func main() {
	l := logger.New("service name", conf.Debug)

	//reading a file example
	filepath := "/filepath"
	
	l.Info("reading file at:", filepath)
	dat, err := os.ReadFile(filepath)
	if err != nil{
		l.With("file_error", "reading file").Error(err)
		os.Exit(1)
    }
	processFile(l, dat)

}

func processFile(l logger.Logger, _ []byte){
	l.Info("processing file")
	//process data
}

Documentation

Index

Constants

View Source
const CorrelationIDKey key = "correlation_id"

CorrelationIDKey is the key to access the correlation id in the context.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Error(args ...any)
	Errorf(template string, args ...any)
	Debug(args ...any)
	Debugf(template string, args ...any)
	Info(args ...any)
	Infof(template string, args ...any)
	Warn(args ...any)
	Warnf(template string, args ...any)
	With(key string, value any) Logger
	WithError(err error) Logger
	WithCorrelation(ctx context.Context) Logger
}

Logger to print information to standard output.

func Mock

func Mock() Logger

Mock returns a new logger mock.

func New

func New(serviceName string, debug bool) Logger

New creates a new logger.

Jump to

Keyboard shortcuts

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