filter

package
Version: v0.0.0-...-18fdafa Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2016 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

The filter package provides a way to filter events from handlers.

The filter itself is just a handler which sits in front of another handler. When the filter handler receives an event, it iterates through all its rules (filter functions), and if they all pass, the event is relayed to the next handler in the chain.

Example
package main

import (
	"fmt"
	"os"

	"github.com/phemmer/sawmill"
	"github.com/phemmer/sawmill/event/formatter"
	"github.com/phemmer/sawmill/handler/filter"
	"github.com/phemmer/sawmill/handler/writer"
)

func main() {
	logger := sawmill.NewLogger()
	defer logger.Stop()

	writer, err := writer.New(os.Stdout, formatter.SIMPLE_FORMAT)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	handler := filter.New(writer).LevelMin(sawmill.NoticeLevel)
	logger.AddHandler("stdout", handler)

	logger.Debug("This is a debug message")
	logger.Error("This is an error message")

}
Output:

This is an error message --

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterFunc

type FilterFunc func(*event.Event) bool

FilterFunc is the signature for a filter used by the handler. The function returns `true` to indicate the event should be allowed, and `false` to indicate it should be dropped.

type FilterHandler

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

func New

func New(nextHandler Handler, filterFuncs ...FilterFunc) *FilterHandler

New creates a new FilterHandler which relays events to the handler specified in `nextHandler`.

If any filterFuncs are provided, they are used as the initial filter list.

func (*FilterHandler) Dedup

func (filterHandler *FilterHandler) Dedup() *FilterHandler

Dedup adds a canned filter to the handler which suppresses duplicate messages.

When an event is received that contains the same message & fields as a previous message, the message is not sent on to the next handler. Once a different message is received, the filter generates a summary message indicating how many duplicates were suppressed.

The return value is the handler itself. This is to allow chaining multiple operations together.

func (*FilterHandler) Event

func (filterHandler *FilterHandler) Event(logEvent *event.Event) error

Event processes an event through the filters, relaying the event to the next handler if all the filters pass.

func (*FilterHandler) Filter

func (filterHandler *FilterHandler) Filter(filterFuncs ...FilterFunc) *FilterHandler

Filter adds a check function to the filter.

The function is passed the event, and should return true if the event is allowed, and false otherwise.

The return value is the handler itself. This is to allow chaining multiple operations together.

func (*FilterHandler) LevelMax

func (filterHandler *FilterHandler) LevelMax(levelMax event.Level) *FilterHandler

LevelMax adds a canned filter to the handler which rejects events with a level greater than the one specified.

The return value is the handler itself. This is to allow chaining multiple operations together.

func (*FilterHandler) LevelMin

func (filterHandler *FilterHandler) LevelMin(levelMin event.Level) *FilterHandler

LevelMin adds a canned filter to the handler which rejects events with a level less than the one specified.

The return value is the handler itself. This is to allow chaining multiple operations together.

type Handler

type Handler interface {
	Event(event *event.Event) error
}

Handler represents a destination for sawmill to send events to.

This is copied from the base sawmill package. Sawmill is not imported so that the base package can import the filter package without a dependency cycle.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL