monolog

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2023 License: MIT Imports: 3 Imported by: 0

README

monolog

Go Version GoDoc codecov Go Report Card tests MIT license

Installation

go get github.com/go-packagist/monolog

Usage

package main

import (
	"github.com/go-packagist/logger"
	"github.com/go-packagist/monolog"
	"github.com/go-packagist/monolog/handler/file"
)

func main() {
	m := monolog.NewLogger("test",
		monolog.WithHandler(
			file.NewHandler(
				"./.testdata/test-file-handler.log",
				file.WithLevel(logger.Debug),
			),
		),
	)

	m.Emergency("test emergency")
	m.Alert("test alert")
	m.Critical("test critical")
	m.Error("test error")
	m.Warning("test warning")
	m.Notice("test notice")
	m.Info("test info")
	m.Debug("test debug")
}

License

The MIT License (MIT). Please see License File for more information.

Thanks

Monolog: I have referenced some architecture designs and made significant adjustments to implement a version in Go programming language.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter interface {
	Format(record *Record) string
}

type FormatterOpt

type FormatterOpt func(Formatter)

type Formatterable

type Formatterable struct {
}

type Handler

type Handler interface {
	IsHandling(*Record) bool
	Handle(*Record) bool
	HandleBatch([]*Record) bool
}

Handler is the interface that all handlers must implement.

type HandlerOpt

type HandlerOpt func(Handler)

HandlerOpt is a function that can be used to configure a Handler.

type Handlerable

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

Handlerable is a struct that can be embedded in a Handler to provide

func NewHandlerable

func NewHandlerable(opts ...HandlerableOpt) *Handlerable

func (*Handlerable) GetDefaultLevel

func (h *Handlerable) GetDefaultLevel() logger.Level

func (*Handlerable) GetFormatter

func (h *Handlerable) GetFormatter() Formatter

func (*Handlerable) GetLevel

func (h *Handlerable) GetLevel() logger.Level

func (*Handlerable) Handle

func (h *Handlerable) Handle(*Record) bool

func (*Handlerable) HandleBatch

func (h *Handlerable) HandleBatch(records []*Record) bool

func (*Handlerable) IsHandling

func (h *Handlerable) IsHandling(record *Record) bool

func (*Handlerable) SetFormatter

func (h *Handlerable) SetFormatter(formatter Formatter)

func (*Handlerable) SetLevel

func (h *Handlerable) SetLevel(level logger.Level)

type HandlerableOpt

type HandlerableOpt func(*Handlerable)

func WithFormatter

func WithFormatter(formatter Formatter) HandlerableOpt

func WithLevel

func WithLevel(level logger.Level) HandlerableOpt

type Logger

type Logger struct {
	logger.Loggerable
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(channel string, opts ...Opt) *Logger

func (*Logger) Channel

func (l *Logger) Channel() string

func (*Logger) Handlers

func (l *Logger) Handlers() []Handler

func (*Logger) Processors

func (l *Logger) Processors() []Processor

type Opt

type Opt func(*Logger)

func WithChannel

func WithChannel(channel string) Opt

func WithHandler

func WithHandler(h Handler) Opt

func WithHandlers

func WithHandlers(hs ...Handler) Opt

func WithProcessor

func WithProcessor(p Processor) Opt

func WithProcessors

func WithProcessors(ps ...Processor) Opt

func WithTimezone

func WithTimezone(tz *time.Location) Opt

type Processor

type Processor interface{}

type Record

type Record struct {
	Channel string       `json:"channel"`
	Message string       `json:"message"`
	Level   logger.Level `json:"level"`
	Time    time.Time    `json:"time"`
	Extra   interface{}  `json:"extra,omitempty"`
}

func (*Record) Marshal

func (r *Record) Marshal() ([]byte, error)

func (*Record) Unmarshal

func (r *Record) Unmarshal(data []byte) error

Directories

Path Synopsis
example
file command
stream command
formatter
handler

Jump to

Keyboard shortcuts

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