Documentation
¶
Index ¶
- type EmailHandler
- func NewAsyncHandler(w io.Writer, opts *slog.HandlerOptions, emailOpts EmailHandlerOpts) (*EmailHandler, func(), error)
- func NewCustomHandler(w io.Writer, opts *slog.HandlerOptions, f SendEmailFunc, json bool) *EmailHandler
- func NewHandler(w io.Writer, opts *slog.HandlerOptions, emailOpts EmailHandlerOpts) (*EmailHandler, error)
- type EmailHandlerOpts
- type GetBodyFunc
- type GetSubjectFunc
- type Mailer
- type SMTPConnectionInfo
- type SendEmailFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EmailHandler ¶
type EmailHandler struct {
// contains filtered or unexported fields
}
EmailHandler is a log/slog compatible handler that writes log records in text or json to user-provided io.Writer and also emails records with defined levels to specified addresses.
func NewAsyncHandler ¶
func NewAsyncHandler(w io.Writer, opts *slog.HandlerOptions, emailOpts EmailHandlerOpts) (*EmailHandler, func(), error)
NewAsyncAsyncHandler creates a new handler than prints log to supplied io.Writer and also asynchronously sends them to a simple SMTP server as an email NewAsyncHandler returns a stopper function that should be called before the application exits, otherwise some log records may be dropped.
func NewCustomHandler ¶
func NewCustomHandler(w io.Writer, opts *slog.HandlerOptions, f SendEmailFunc, json bool) *EmailHandler
NewCustomHandler creates a new handler that prints logs to supplied io.Writer and also passes them to user-defined function
func NewHandler ¶
func NewHandler(w io.Writer, opts *slog.HandlerOptions, emailOpts EmailHandlerOpts) (*EmailHandler, error)
NewHandler creates a new handler than prints log to supplied io.Writer and also sends them to a simple SMTP server as an email
type EmailHandlerOpts ¶
type EmailHandlerOpts struct { // FromAddr is a from email address FromAddr string // ToAddrs is a slice of emails that log records will be sent to ToAddrs []string // JSON sets log record format (true = pretty JSON, false = text) JSON bool // Level determines the minimum log level at which emails will be sent. Can be different from level in `opts` parameter in NewHandler Level slog.Level // GetSubject is a user-defined function for making custom email subject. By default log record level name is used. GetSubject GetSubjectFunc // GetBody is a user-defined function for making custom email body. By default log record text is used. GetBody GetBodyFunc // ConnectionInfo contains information about SMTP server. ConnectionInfo SMTPConnectionInfo // AsyncQueueSize specifies how many records can be queued before logger will have to actually wait for them to be sent // Ignored if handler is not asynchronous // Default: 1 AsyncQueueSize int // contains filtered or unexported fields }
EmailHandlerOpts contains options specific to EmailHandler If SendEmail is not provided, ConnectionInfo will be used
type GetBodyFunc ¶
GetBodyFunc is a function that accepts an slog record and rendered output from slog's standard text or json handler and returns a body for a letter
type GetSubjectFunc ¶
GetSubjectFunc is a function that accepts an slog record and rendered output from slog's standard text or json handler and returns a subject for a letter