processor

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package processor provides the building blocks to create processors, which are used to process messages before they are printed. It also provides a collection of built-in processors.

NOTES: - Processors are executed in the order they are added to the pipeline. - It's the implementator's responsibility to check if the message has content. Sypl doesn't touch the message's content - it pass thru as it's, raw - as any logger. Only processors are able to change the message's content. Use the `IsEmpty` help method to check if the message has content.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProcessingError

func NewProcessingError(m message.IMessage, e error) error

NewProcessingError returns a new `ProcessingError`.

Types

type Casing

type Casing string

Casing definition, e.g.: Upper, Lower, Title, etc.

const (
	// Lowercase casing.
	Lowercase Casing = "lowercase"

	// Uppercase casing.
	Uppercase Casing = "uppercase"
)

type IProcessor

type IProcessor interface {
	meta.IMeta

	// String interface.
	String() string

	// Run the processor, if enabled.
	Run(m message.IMessage) error
}

IProcessor specifies what a processor does.

func ChangeFirstCharCase

func ChangeFirstCharCase(casing Casing) IProcessor

ChangeFirstCharCase changes message content's first char to the specified case.

Notes: - `casing` because `case` is a reserved word. - Order matters! If this comes after another processor like the Prefixer, it will change the case of the first char of the Prefix mask, not the message content!

func ColorizeBasedOnLevel

func ColorizeBasedOnLevel(levelColorMap map[level.Level]color.Color) IProcessor

ColorizeBasedOnLevel colorize messages based on the specified levels.

func ColorizeBasedOnWord

func ColorizeBasedOnWord(wordColorMap map[string]color.Color) IProcessor

ColorizeBasedOnWord colorize a messages with the specified colors if a message contains a specific word.

func Decolourizer

func Decolourizer() IProcessor

Decolourizer removes any colour.

func ErrorSimulator

func ErrorSimulator(msg string) IProcessor

ErrorSimulator simulates an error in the pipeline.

func ForceBasedOnLevel

func ForceBasedOnLevel(levels ...level.Level) IProcessor

ForceBasedOnLevel force messages to be printed based on the specified levels.

func MuteBasedOnLevel

func MuteBasedOnLevel(levels ...level.Level) IProcessor

MuteBasedOnLevel mute messages based on the specified levels.

func New

func New(name string, f RunFunc) IProcessor

New is the Processor factory.

func PrefixBasedOnMask

func PrefixBasedOnMask(timestampFormat string) IProcessor

PrefixBasedOnMask prefixes messages with the predefined mask.

Example: 2021-06-22 12:51:46.089 [80819] [CLI] [Info].

func PrefixBasedOnMaskExceptForLevels

func PrefixBasedOnMaskExceptForLevels(timestampFormat string, levels ...level.Level) IProcessor

PrefixBasedOnMaskExceptForLevels is a specialized version of the `PrefixBasedOnMask`. It prefixes all messages, except for the specified levels.

func Prefixer

func Prefixer(prefix string) IProcessor

Prefixer prefixes a message with the specified `prefix`.

func PrintOnlyAtLevel

func PrintOnlyAtLevel(levels ...level.Level) IProcessor

PrintOnlyAtLevel prints only if message is at the specified level.

func PrintOnlyIfNotTaggedWith added in v1.6.6

func PrintOnlyIfNotTaggedWith(tags ...string) IProcessor

PrintOnlyIfNotTaggedWith prints only if message contains the specified tag.

func PrintOnlyIfTagged

func PrintOnlyIfTagged(tag string) IProcessor

PrintOnlyIfTagged prints only if message contains the specified tag.

func Suffixer

func Suffixer(suffix string) IProcessor

Suffixer suffixes a message with the specified `suffix`.

type ProcessingError

type ProcessingError struct {
	// Cause is the underlying case of the failure.
	Cause error

	// Message when the failured happened.
	Message message.IMessage

	// OutputName is the name of the output in-use.
	OutputName string

	// ProcessorName is the name of the processor in-use.
	ProcessorName string
}

ProcessingError is thrown when a processor fails.

func (*ProcessingError) Error

func (p *ProcessingError) Error() string

Error interface implementation.

type RunFunc

type RunFunc func(m message.IMessage) error

RunFunc specifies the function used to process a message.

Jump to

Keyboard shortcuts

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