monolog

package module
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 2 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/stream"
	"os"
)

func main() {
	curPath, _ := os.Getwd()

	file, _ := os.OpenFile(curPath+"/.testdata/test-example-stream-handler.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)

	m := monolog.NewLogger("test", monolog.WithHandlers(
		stream.NewHandler(file, stream.WithLevel(logger.Error)),      // error above to file
		stream.NewHandler(os.Stdout, stream.WithLevel(logger.Info))), // else info above to stdout
	)

	m.Emergency("test emergency")
	m.Info("test info")
	m.Error("test error")
}

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 Handleable

type Handleable func(record *Record) bool

Handleable is a function that can be used as a Handler.

func (Handleable) Handle

func (h Handleable) Handle(record *Record) bool

Handle is a function that can be used as a Handler.

func (Handleable) HandleBatch

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

HandleBatch is a function that can be used as a Handler.

type Handler

type Handler interface {
	IsHandling(*Record) bool
	Handle(*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 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
	Message   string
	Level     logger.Level
	Time      time.Time
	Extra     interface{}
	Formatted string
}

Directories

Path Synopsis
example
stream command
formatter
handler

Jump to

Keyboard shortcuts

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