logging

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2021 License: MIT Imports: 8 Imported by: 9

README

ao-concepts logging module

CI codecov

This module provides a logger that fits for use within the ao-concepts ecosystem.

Information

The ao-concepts ecosystem is still under active development and therefore the API of this module may have breaking changes until there is a first stable release.

If you are interested in contributing to this project, feel free to open a issue to discus a new feature, enhancement or improvement. If you found a bug or security vulnerability in this package, please start a issue, or open a PR against master.

Installation

go get -u github.com/ao-concepts/logging

Usage

The DefaultLogger is a wrapper around github.com/rs/zerolog It integrates into gorm.io/gorm by using the CreateGormLogger function.

You can specify a io.Writer that is used by the logger. By default the logger uses os.Stdout.

log := logging.New(logging.Warn, nil)

log.ErrError(err)
log.Error("string", arg1, arg2)

Used packages

This project uses some really great packages. Please make sure to check them out!

Package Usage
github.com/rs/zerolog The default logger
github.com/stretchr/testify Testing
gorm.io/gorm Database access

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultLogger

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

DefaultLogger default logging controller

func (*DefaultLogger) CreateGormLogger

func (l *DefaultLogger) CreateGormLogger() logger.Interface

CreateGormLogger creates a mock of this logger for usage with gorm

func (*DefaultLogger) Debug

func (l *DefaultLogger) Debug(s string, args ...interface{})

Debug log something at debug level

func (*DefaultLogger) ErrDebug

func (l *DefaultLogger) ErrDebug(err error)

ErrDebug log an error at debug level

func (*DefaultLogger) ErrError

func (l *DefaultLogger) ErrError(err error)

ErrError log an error at error level

func (*DefaultLogger) ErrFatal

func (l *DefaultLogger) ErrFatal(err error)

ErrFatal log an error at fatal level. This will panic!

func (*DefaultLogger) ErrInfo

func (l *DefaultLogger) ErrInfo(err error)

ErrInfo log an error at info level

func (*DefaultLogger) ErrWarn

func (l *DefaultLogger) ErrWarn(err error)

ErrWarn log an error at warning level

func (*DefaultLogger) Error

func (l *DefaultLogger) Error(s string, args ...interface{})

Error log something at error level

func (*DefaultLogger) Fatal

func (l *DefaultLogger) Fatal(s string, args ...interface{})

Fatal log something at fatal level. This will panic!

func (*DefaultLogger) GetLevel

func (l *DefaultLogger) GetLevel() Level

GetLevel returns the current error level

func (*DefaultLogger) Info

func (l *DefaultLogger) Info(s string, args ...interface{})

Info log something at info level

func (*DefaultLogger) Warn

func (l *DefaultLogger) Warn(s string, args ...interface{})

Warn log something at warning level

func (*DefaultLogger) Write

func (l *DefaultLogger) Write(p []byte) (n int, err error)

Write data to the logger (info level is used)

type Level

type Level uint8

Level level of a logging

const (
	// Debug logging level
	Debug Level = 1
	// Info logging level
	Info Level = 2
	// Warn logging level
	Warn Level = 3
	// Error logging level
	Error Level = 4
	// Fatal logging level
	Fatal Level = 5
)

type Logger

type Logger interface {
	Fatal(s string, args ...interface{})
	ErrFatal(err error)
	Error(s string, args ...interface{})
	ErrError(err error)
	Warn(s string, args ...interface{})
	ErrWarn(err error)
	Info(s string, args ...interface{})
	ErrInfo(err error)
	Debug(s string, args ...interface{})
	ErrDebug(err error)
	CreateGormLogger() logger.Interface
	Write(p []byte) (n int, err error)
	GetLevel() Level
}

Logger interface

func New

func New(level Level, writer io.Writer) Logger

New logger constructor, creates a default logger instance. Uses os.Stdout if the writer parameter is nil.

Jump to

Keyboard shortcuts

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