llog: github.com/syyongx/llog/handler Index | Files

package handler

import "github.com/syyongx/llog/handler"

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

Index

Package Files

Processing.go buffer.go file.go filter.go formattable.go handler.go mail.go net.go processable.go rotating_file.go syslog.go

Constants

const (
    FlushModeTicker = iota + 1
    FlushModeLimit
)

available FlushMode values

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

some rotating date formats

type Buffer Uses

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

Buffer struct definition

func NewBuffer Uses

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

NewBuffer New async handler bufSize: channel buffer size.

func (*Buffer) Close Uses

func (b *Buffer) Close()

Close close

func (*Buffer) Handle Uses

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

Handle handles a record.

func (*Buffer) HandleBatch Uses

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

HandleBatch Handles a set of records.

type Bufio Uses

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

Bufio struct definition

type File Uses

type File struct {
    Processing

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

File handler.

func NewFile Uses

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

NewFile New file handler

func (*File) Close Uses

func (f *File) Close()

Close writer

func (*File) Flush Uses

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

Flush flush

func (*File) SetBufio Uses

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

SetBufio Set flush config.

func (*File) Write Uses

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

Write to file.

type Filter Uses

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

Filter struct definition

func NewFilter Uses

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

NewFilter New Filter

func (*Filter) GetAcceptedLevels Uses

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

GetAcceptedLevels Get acceptedLevels

func (*Filter) Handle Uses

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

Handle log record

func (*Filter) HandleBatch Uses

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

HandleBatch log records

func (*Filter) IsHandling Uses

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

IsHandling Is Handling

func (*Filter) SetAcceptedLevels Uses

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

SetAcceptedLevels Set acceptedLevels

type FlushMode Uses

type FlushMode uint8

FlushMode type

type Formattable Uses

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

Formattable struct definition

func (*Formattable) GetDefaultFormatter Uses

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

GetDefaultFormatter Gets the default formatter.

func (*Formattable) GetFormatter Uses

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

GetFormatter Get formatter

func (*Formattable) SetFormatter Uses

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

SetFormatter Set formatter

type Handler Uses

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

Handler struct definition

func (*Handler) GetBubble Uses

func (h *Handler) GetBubble() bool

GetBubble Get bubble

func (*Handler) GetLevel Uses

func (h *Handler) GetLevel() int

GetLevel Get level

func (*Handler) IsHandling Uses

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

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

func (*Handler) SetBubble Uses

func (h *Handler) SetBubble(bubble bool)

SetBubble Set bubble

func (*Handler) SetLevel Uses

func (h *Handler) SetLevel(level int)

SetLevel Set level

type Mail Uses

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 Uses

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

NewMail new mail handler

func (*Mail) ContentType Uses

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 Uses

func (m *Mail) Encoding() string

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

func (*Mail) SetContentType Uses

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 Uses

func (m *Mail) SetEncoding(encoding string)

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

func (*Mail) Write Uses

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

Write to network.

type Net Uses

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 Uses

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

NewNet new net handler

func (*Net) Close Uses

func (n *Net) Close()

Close connect.

func (*Net) Write Uses

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

Write to network.

type Processable Uses

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

Processable struct definition

func (*Processable) PopProcessor Uses

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

PopProcessor pop processor

func (*Processable) ProcessRecord Uses

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

ProcessRecord Processes a record.

func (*Processable) PushProcessor Uses

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

PushProcessor push processor

type Processing Uses

type Processing struct {
    Handler
    Processable
    Formattable

    Writer func(*types.Record)
}

Processing struct definition

func (*Processing) Handle Uses

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

Handle a record.

func (*Processing) HandleBatch Uses

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

HandleBatch Handles a set of records.

type RotatingFile Uses

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 Uses

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 Uses

func (rf *RotatingFile) Close()

Close the handler.

func (*RotatingFile) SetFilenameFormat Uses

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

SetFilenameFormat Set filename format.

func (*RotatingFile) Write Uses

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

Write to file.

type Syslog Uses

type Syslog struct {
    Processing

    SysWriter *syslog.Writer
}

Syslog struct definition

func NewSyslog Uses

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 Uses

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

GetDefaultFormatter Gets the default syslog formatter.

func (*Syslog) Write Uses

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

Write to console.

Package handler imports 16 packages (graph) and is imported by 1 packages. Updated 2019-05-31. Refresh now. Tools for package owners.