logger

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 3 Imported by: 0

README

Hyperscale logger Last release Documentation

Go Report Card

Branch Status Coverage
master Build Status Coveralls

The Hyperscale logger is an standard interface for abstract logger provider

Example

package main

import (
    "fmt"
    "github.com/hyperscale-stack/logger"
)

func main() {
    l := NewStandardLogger(&outBuf, &errBuf)

	l.Panic("my panic message without option")
	l.Fatal("my fatal message without option")
	l.Error("my error message without option")
	l.Warning("my warning message without option")
	l.Info("my info message without option")
	l.Debug("my debug message without option")
	l.Trace("my trace message without option")

    labels := map[string]interface{}{
		"foo": "bar",
	}

	l.Panic("my panic message with option labels", WithLabels(labels))
	l.Fatal("my fatal message with option labels", WithLabels(labels))
	l.Error("my error message with option labels", WithLabels(labels))
	l.Warning("my warning message with option labels", WithLabels(labels))
	l.Info("my info message with option labels", WithLabels(labels))
	l.Debug("my debug message with option labels", WithLabels(labels))
	l.Trace("my trace message with option labels", WithLabels(labels))


    l.Panic("my panic message with option format: %s => %d", WithFormat("foo", 1))
	l.Fatal("my fatal message with option format: %s => %d", WithFormat("foo", 1))
	l.Error("my error message with option format: %s => %d", WithFormat("foo", 1))
	l.Warning("my warning message with option format: %s => %d", WithFormat("foo", 1))
	l.Info("my info message with option format: %s => %d", WithFormat("foo", 1))
	l.Debug("my debug message with option format: %s => %d", WithFormat("foo", 1))
	l.Trace("my trace message with option format: %s => %d", WithFormat("foo", 1))
}

License

Hyperscale logger is licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Labels  map[string]interface{}
	Formats []interface{}
}

type LevelType

type LevelType int

LevelType type.

const (
	LevelPanic LevelType = iota
	LevelFatal
	LevelError
	LevelWarning
	LevelInfo
	LevelDebug
	LevelTrace
)

LevelType consts.

func (LevelType) String

func (l LevelType) String() string

type Logger

type Logger interface {
	// Log with an arbitrary level.
	Log(level LevelType, message string, options ...Option)
	Panic(message string, options ...Option)
	Fatal(message string, options ...Option)
	Error(message string, options ...Option)
	Warning(message string, options ...Option)
	Info(message string, options ...Option)
	Debug(message string, options ...Option)
	Trace(message string, options ...Option)
}

Logger describes a logger instance.

func NewStandardLogger

func NewStandardLogger(out io.Writer, err io.Writer) Logger

type LoggerAware

type LoggerAware interface {
	SetLogger(logger Logger)
}

LoggerAware describes a logger-aware instance.

type Nop

type Nop struct{}

func (Nop) Debug

func (Nop) Debug(message string, options ...Option)

func (Nop) Error

func (Nop) Error(message string, options ...Option)

func (Nop) Fatal

func (Nop) Fatal(message string, options ...Option)

func (Nop) Info

func (Nop) Info(message string, options ...Option)

func (Nop) Log

func (Nop) Log(level LevelType, message string, options ...Option)

func (Nop) Panic

func (Nop) Panic(message string, options ...Option)

func (Nop) Trace

func (Nop) Trace(message string, options ...Option)

func (Nop) Warning

func (Nop) Warning(message string, options ...Option)

type Option

type Option func(*Context)

func WithFormat

func WithFormat(formats ...interface{}) Option

WithFormat add formats args to logger.Context.

func WithLabels

func WithLabels(labels map[string]interface{}) Option

WithLabels add labels to logger.Context.

type Standard

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

func (*Standard) Debug

func (l *Standard) Debug(message string, options ...Option)

func (*Standard) Error

func (l *Standard) Error(message string, options ...Option)

func (*Standard) Fatal

func (l *Standard) Fatal(message string, options ...Option)

func (*Standard) Info

func (l *Standard) Info(message string, options ...Option)

func (*Standard) Log

func (l *Standard) Log(level LevelType, message string, options ...Option)

func (*Standard) Panic

func (l *Standard) Panic(message string, options ...Option)

func (*Standard) Trace

func (l *Standard) Trace(message string, options ...Option)

func (*Standard) Warning

func (l *Standard) Warning(message string, options ...Option)

Jump to

Keyboard shortcuts

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