handler

package
v0.0.0-...-e8f9f86 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2020 License: MIT Imports: 16 Imported by: 1

Documentation

Overview

Package handler provides some commonly used handlers。 such as: file, mail, syslog and more

Index

Constants

View Source
const (
	FlushModeTicker = iota + 1
	FlushModeLimit
)

available FlushMode values

View Source
const (
	FilePerDay   string = "2006-01-02"
	FilePerMonth string = "2006-01"
	FilePerYear  string = "2006"
)

some rotating date formats

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	Handler
	// contains filtered or unexported fields
}

Buffer struct definition

func NewBuffer

func NewBuffer(handler types.IHandler, bufSize, level int, bubble bool) *Buffer

NewBuffer New async handler bufSize: channel buffer size.

func (*Buffer) Close

func (b *Buffer) Close()

Close close

func (*Buffer) Handle

func (b *Buffer) Handle(record *types.Record) bool

Handle handles a record.

func (*Buffer) HandleBatch

func (b *Buffer) HandleBatch(records []*types.Record)

HandleBatch Handles a set of records.

type Bufio

type Bufio struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Bufio struct definition

type File

type File struct {
	Processing

	Path     string
	FilePerm os.FileMode
	Fd       *os.File
	Bufio
}

File handler.

func NewFile

func NewFile(path string, filePerm os.FileMode, level int, bubble bool) *File

NewFile New file handler

func (*File) Close

func (f *File) Close()

Close writer

func (*File) Flush

func (f *File) Flush() (err error)

Flush flush

func (*File) SetBufio

func (f *File) SetBufio(size int, mode FlushMode, interval time.Duration) error

SetBufio Set flush config.

func (*File) Write

func (f *File) Write(record *types.Record)

Write to file.

type Filter

type Filter struct {
	Handler
	Processable
	// contains filtered or unexported fields
}

Filter struct definition

func NewFilter

func NewFilter(handler types.IHandler, minLevels, maxLevels []int, bubble bool) *Filter

NewFilter New Filter

func (*Filter) GetAcceptedLevels

func (f *Filter) GetAcceptedLevels() map[int]int

GetAcceptedLevels Get acceptedLevels

func (*Filter) Handle

func (f *Filter) Handle(record *types.Record) bool

Handle log record

func (*Filter) HandleBatch

func (f *Filter) HandleBatch(records []*types.Record)

HandleBatch log records

func (*Filter) IsHandling

func (f *Filter) IsHandling(record *types.Record) bool

IsHandling Is Handling

func (*Filter) SetAcceptedLevels

func (f *Filter) SetAcceptedLevels(minLevels, maxLevels []int) map[int]int

SetAcceptedLevels Set acceptedLevels

type FlushMode

type FlushMode uint8

FlushMode type

type Formattable

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

Formattable struct definition

func (*Formattable) GetDefaultFormatter

func (f *Formattable) GetDefaultFormatter() types.Formatter

GetDefaultFormatter Gets the default formatter.

func (*Formattable) GetFormatter

func (f *Formattable) GetFormatter() types.Formatter

GetFormatter Get formatter

func (*Formattable) SetFormatter

func (f *Formattable) SetFormatter(formatter types.Formatter)

SetFormatter Set formatter

type Handler

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

Handler struct definition

func (*Handler) GetBubble

func (h *Handler) GetBubble() bool

GetBubble Get bubble

func (*Handler) GetLevel

func (h *Handler) GetLevel() int

GetLevel Get level

func (*Handler) IsHandling

func (h *Handler) IsHandling(record *types.Record) bool

IsHandling Checks whether the given record will be handled by this handler.

func (*Handler) SetBubble

func (h *Handler) SetBubble(bubble bool)

SetBubble Set bubble

func (*Handler) SetLevel

func (h *Handler) SetLevel(level int)

SetLevel Set level

type Mail

type Mail struct {
	Processing

	Addr     string   // SMTP server address
	Username string   // SMTP server login username
	Password string   // SMTP server login password
	Subject  string   // The subject of the email
	From     string   // The sender of the mail
	To       []string // The email addresses to which the message will be sent
	// contains filtered or unexported fields
}

Mail handler struct definition

func NewMail

func NewMail(address, username, password, from, subject string, to []string, level int, bubble bool) *Mail

NewMail new mail handler

func (*Mail) ContentType

func (m *Mail) ContentType() string

ContentType Get the content type of the email - Defaults to text/plain. Use text/html for HTML

func (*Mail) Encoding

func (m *Mail) Encoding() string

Encoding Get the encoding for the message - Defaults to UTF-8

func (*Mail) SetContentType

func (m *Mail) SetContentType(contentType string)

SetContentType Set the content type of the email - Defaults to text/plain. Use text/html for HTML

func (*Mail) SetEncoding

func (m *Mail) SetEncoding(encoding string)

SetEncoding Set the encoding for the message - Defaults to UTF-8

func (*Mail) Write

func (m *Mail) Write(record *types.Record)

Write to network.

type Net

type Net struct {
	Processing

	// Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only),
	// "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4"
	// (IPv4-only), "ip6" (IPv6-only), "unix", "unixgram" and
	// "unixpacket".
	Network    string
	Address    string
	Persistent bool
	BufferSize int
	// contains filtered or unexported fields
}

Net handler struct definition

func NewNet

func NewNet(bufferSize int, persistent bool, level int, bubble bool) *Net

NewNet new net handler

func (*Net) Close

func (n *Net) Close()

Close connect.

func (*Net) Write

func (n *Net) Write(record *types.Record)

Write to network.

type Processable

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

Processable struct definition

func (*Processable) PopProcessor

func (p *Processable) PopProcessor() types.Processor

PopProcessor pop processor

func (*Processable) ProcessRecord

func (p *Processable) ProcessRecord(record *types.Record)

ProcessRecord Processes a record.

func (*Processable) PushProcessor

func (p *Processable) PushProcessor(types.Processor)

PushProcessor push processor

type Processing

type Processing struct {
	Handler
	Processable
	Formattable

	Writer func(*types.Record)
}

Processing struct definition

func (*Processing) Handle

func (p *Processing) Handle(record *types.Record) bool

Handle a record.

func (*Processing) HandleBatch

func (p *Processing) HandleBatch(records []*types.Record)

HandleBatch Handles a set of records.

type RotatingFile

type RotatingFile struct {
	*File

	sync.Mutex
	// contains filtered or unexported fields
}

RotatingFile Stores logs to files that are rotated every day and a limited number of files are kept.

This rotation is only intended to be used as a workaround. Using logrotate to handle the rotation is strongly encouraged when you can use it.

func NewRotatingFile

func NewRotatingFile(filename string, filePerm os.FileMode, maxFiles, level int, bubble bool) *RotatingFile

NewRotatingFile New rotatingFile handler level: The minimum logging level at which this handler will be triggered bubble: Whether the messages that are handled can bubble up the stack or not filePerm: Optional file permissions (default (0644) are only for owner read/write)

func (*RotatingFile) Close

func (rf *RotatingFile) Close()

Close the handler.

func (*RotatingFile) SetFilenameFormat

func (rf *RotatingFile) SetFilenameFormat(filenameFormat, dateFormat string) error

SetFilenameFormat Set filename format.

func (*RotatingFile) Write

func (rf *RotatingFile) Write(record *types.Record)

Write to file.

type Syslog

type Syslog struct {
	Processing

	SysWriter *syslog.Writer
}

Syslog struct definition

func NewSyslog

func NewSyslog(priority syslog.Priority, tag string, level int, bubble bool) (*Syslog, error)

NewSyslog New establishes a new connection to the system log daemon. Each write to the returned writer sends a log message with the given priority (a combination of the syslog facility and severity) and prefix tag. If tag is empty, the os.Args[0] is used.

func (*Syslog) GetDefaultFormatter

func (s *Syslog) GetDefaultFormatter() types.Formatter

GetDefaultFormatter Gets the default syslog formatter.

func (*Syslog) Write

func (s *Syslog) Write(record *types.Record)

Write to console.

Jump to

Keyboard shortcuts

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