logger

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Logger

License Release

Logger is a go package that provides a simple and easy to use logging interface. It is designed to be used in a variety of applications and provides a simple way to log messages.


Quick Start

go get github.com/RevittConsulting/logger

Features

  • Simple and easy to use
  • Get observed logs for testing
  • Loki support

Loki Configuration

Run this on app startup to enable loki logging.

InitLoggerConfig(&Config{
    LokiAddress: "http://localhost:3100",
    Labels:      map[string]string{"app": "My App", "env": "local"},
    UsingLoki:   true,
})

Log to file

Add these values to config

loggerCfg := &logger.Config{
    LogToFile:   true,
    LogFilePath: "log.txt",
}
logger.InitLoggerConfig(loggerCfg)

Contributing

Found a bug or want to suggest a feature? Feel free to create an issue or make a pull request.


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorLevel

func ErrorLevel() zapcore.Level

ErrorLevel returns zapcore error level

func GetObservedLogs

func GetObservedLogs() *observer.ObservedLogs

GetObservedLogs returns observed logs for testing purposes

func InitLoggerConfig added in v1.1.0

func InitLoggerConfig(config *Config)

InitLoggerConfig initialises logger with config. Labels example: map[string]string{"app": My App, env: production}

Types

type Config added in v1.1.0

type Config struct {
	LokiAddress string
	Labels      map[string]string
	UsingLoki   bool
	LogToFile   bool
	LogFilePath string
}

type Zaplog

type Zaplog struct {
	*zap.Logger
}

func Log

func Log() *Zaplog

Log is invoking Zap Logger function

func (*Zaplog) DebugErr

func (z *Zaplog) DebugErr(e error, fields ...zapcore.Field) *Zaplog

DebugErr is invoking Zap Logger function with error message and fields and log level Debug

func (*Zaplog) ErrorAlert added in v1.3.0

func (z *Zaplog) ErrorAlert(e error, fields ...zapcore.Field) *Zaplog

ErrorAlert is invoking Zap Logger function with error message and fields and log level Error

func (*Zaplog) ErrorErr

func (z *Zaplog) ErrorErr(e error, fields ...zapcore.Field) *Zaplog

ErrorErr is invoking Zap Logger function with error message and fields and log level Error

func (*Zaplog) InfoErr

func (z *Zaplog) InfoErr(e error, fields ...zapcore.Field) *Zaplog

InfoErr is invoking Zap Logger function with error message and fields and log level Info

func (*Zaplog) PanicErr

func (z *Zaplog) PanicErr(e error, fields ...zapcore.Field) *Zaplog

PanicErr is invoking Zap Logger function with error message and fields and log level Panic

func (*Zaplog) WarnAlert added in v1.3.0

func (z *Zaplog) WarnAlert(e error, fields ...zapcore.Field) *Zaplog

WarnAlert is invoking Zap Logger function with error message and fields and log level Warn

func (*Zaplog) WarnErr

func (z *Zaplog) WarnErr(e error, fields ...zapcore.Field) *Zaplog

WarnErr is invoking Zap Logger function with error message and fields and log level Warn

Jump to

Keyboard shortcuts

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