Documentation ¶
Index ¶
- func ContextWithConditionalHandlerOptions(ctx context.Context, opts ConditionalHandlerOptions) context.Context
- func ContextWithFailoverHandlerOptions(ctx context.Context, opts FailoverHandlerOptions) context.Context
- func ContextWithFileHandlerOptions(ctx context.Context, opts FileHandlerOptions) context.Context
- func ContextWithMultiHandlerOptions(ctx context.Context, opts MultiHandlerOptions) context.Context
- func ContextWithPipeHandlerOptions(ctx context.Context, opts PipeHandlerOptions) context.Context
- func ContextWithRoundRobinHandlerOptions(ctx context.Context, opts RoundRobinHandlerOptions) context.Context
- func NewConditionalHandler(opts ConditionalHandlerOptions, cond ...*Condition) *conditionalHandler
- func NewConsoleHandler(opts ConsoleHandlerOptions) *consoleHandler
- func NewFailoverHandler(opts FailoverHandlerOptions, handlers ...slog.Handler) *failoverHandler
- func NewFileHandler(opts FileHandlerOptions) (*fileHandler, error)
- func NewHTTPHandler(opts HTTPHandlerOptions) (*httpHandler, error)
- func NewJSONHandler(opts JSONHandlerOptions) *jsonHandler
- func NewMultiHandler(opts MultiHandlerOptions, handler ...slog.Handler) *multiHandler
- func NewPipeHandler(opts PipeHandlerOptions, next slog.Handler) *pipeHandler
- func NewRoundRobinHandler(opts RoundRobinHandlerOptions, handlers ...slog.Handler) *roundRobinHandler
- type Condition
- type ConditionMatchesFn
- type ConditionalHandlerOptions
- type ConsoleHandlerOptions
- type FailoverHandlerOptions
- type FileHandlerOptions
- type HTTPHandlerOptions
- type JSONHandlerOptions
- type MultiHandlerOptions
- type PipeHandlerFn
- type PipeHandlerOptions
- type RoundRobinHandlerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithConditionalHandlerOptions ¶ added in v0.5.0
func ContextWithConditionalHandlerOptions(ctx context.Context, opts ConditionalHandlerOptions) context.Context
ContextWithConditionalHandlerOptions adds the options to the given context and returns the new context.
func ContextWithFailoverHandlerOptions ¶ added in v0.5.0
func ContextWithFailoverHandlerOptions(ctx context.Context, opts FailoverHandlerOptions) context.Context
ContextWithFailoverHandlerOptions adds the options to the given context and returns the new context.
func ContextWithFileHandlerOptions ¶ added in v0.5.0
func ContextWithFileHandlerOptions(ctx context.Context, opts FileHandlerOptions) context.Context
ContextWithFileHandlerOptions adds the options to the given context and returns the new context.
func ContextWithMultiHandlerOptions ¶ added in v0.5.0
func ContextWithMultiHandlerOptions(ctx context.Context, opts MultiHandlerOptions) context.Context
ContextWithMultiHandlerOptions adds the options to the given context and returns the new context.
func ContextWithPipeHandlerOptions ¶ added in v0.5.0
func ContextWithPipeHandlerOptions(ctx context.Context, opts PipeHandlerOptions) context.Context
ContextWithPipeHandlerOptions adds the options to the given context and returns the new context.
func ContextWithRoundRobinHandlerOptions ¶ added in v0.5.0
func ContextWithRoundRobinHandlerOptions(ctx context.Context, opts RoundRobinHandlerOptions) context.Context
ContextWithRoundRobinHandlerOptions adds the options to the given context and returns the new context.
func NewConditionalHandler ¶
func NewConditionalHandler(opts ConditionalHandlerOptions, cond ...*Condition) *conditionalHandler
NewConditionalHandler creates a new handler object.
func NewConsoleHandler ¶
func NewConsoleHandler(opts ConsoleHandlerOptions) *consoleHandler
NewConsoleHandler creates a new handler object.
func NewFailoverHandler ¶
func NewFailoverHandler(opts FailoverHandlerOptions, handlers ...slog.Handler) *failoverHandler
NewFailoverHandler creates a new handler object.
func NewFileHandler ¶
func NewFileHandler(opts FileHandlerOptions) (*fileHandler, error)
NewFileHandler creates a new handler object.
func NewHTTPHandler ¶ added in v0.6.0
func NewHTTPHandler(opts HTTPHandlerOptions) (*httpHandler, error)
NewHTTPHandler creates a new handler object.
func NewJSONHandler ¶
func NewJSONHandler(opts JSONHandlerOptions) *jsonHandler
NewJSONHandler creates a new handler object.
func NewMultiHandler ¶
func NewMultiHandler(opts MultiHandlerOptions, handler ...slog.Handler) *multiHandler
NewMultiHandler creates a new handler object.
func NewPipeHandler ¶
func NewPipeHandler(opts PipeHandlerOptions, next slog.Handler) *pipeHandler
NewPipeHandler creates a new object.
func NewRoundRobinHandler ¶
func NewRoundRobinHandler(opts RoundRobinHandlerOptions, handlers ...slog.Handler) *roundRobinHandler
NewRoundRobinHandler creates a new handler object.
Types ¶
type Condition ¶ added in v0.6.2
type Condition struct {
// contains filtered or unexported fields
}
Condition defines the condition(s) which must all be true in order to log a message to the given handler.
If no conditions are specified, the handler will always be used to log the messages.
func NewCondition ¶
func NewCondition(handler slog.Handler, matcher ...ConditionMatchesFn) *Condition
NewCondition defines one or more functions to call to determine whether or not to log to the given handler.
If no conditions are specified, the handler will always be used to log the messages.
func (*Condition) Add ¶ added in v0.6.2
func (c *Condition) Add(matcher ...ConditionMatchesFn) *Condition
Add simply adds one or more additional conditions to the existing condition and returns the updated object.
func (Condition) WithCondition ¶ added in v0.6.2
func (c Condition) WithCondition(matcher ...ConditionMatchesFn) *Condition
WithCondition adds one or more additional conditions to the existing condition and returns a new condition.
type ConditionMatchesFn ¶
ConditionMatchesFn is called to determine whether or not the given record should be logged.
type ConditionalHandlerOptions ¶
type ConditionalHandlerOptions struct { // ContinueOnError determines whether or not to continue looking for handlers to log to if an error occurs while // logging with a matching handler or running any middleware. ContinueOnError bool // EnableAsync will execute the Handle() function in a separate goroutine in case there are time-consuming // conditions which must be evaluated before determining which handler(s) to use for writing the record. // // When async is enabled, you should be sure to call the Shutdown() function or use the slogx.Shutdown() // function to ensure all goroutines are finished and any pending records have been written. EnableAsync bool }
ConditionalHandlerOptions holds the options available when creating the conditionalHandler object.
func ConditionalHandlerOptionsFromContext ¶ added in v0.5.0
func ConditionalHandlerOptionsFromContext(ctx context.Context) *ConditionalHandlerOptions
ConditionalHandlerOptionsFromContext retrieves the options from the context.
If the options are not set in the context, a set of default options is returned instead.
func DefaultConditionalHandlerOptions ¶ added in v0.2.0
func DefaultConditionalHandlerOptions() ConditionalHandlerOptions
DefaultConditionalHandlerOptions returns a default set of options for the handler.
type ConsoleHandlerOptions ¶
type ConsoleHandlerOptions struct { // Level is the minimum log level to write to the handler. // // If this is nil, it defaults to slogx.LevelInfo. Level *slogx.LevelVar // RecordFormatter specifies the formatter to use to format the record before writing it to the writer. // // If no formatter is supplied, a colorized formatter.DefaultConsoleFormatter is used to format the output. RecordFormatter formatter.ColorBufferFormatter // Writer is where to write the output to. // // By default, messages are written to os.Stdout if not supplied. Writer io.Writer }
ConsoleHandlerOptions holds the options for the console handler.
func DefaultConsoleHandlerOptions ¶ added in v0.2.0
func DefaultConsoleHandlerOptions() ConsoleHandlerOptions
DefaultConsoleHandlerOptions returns a default set of options for the handler.
func GetConsoleHandlerOptionsFromContext ¶ added in v0.2.0
func GetConsoleHandlerOptionsFromContext(ctx context.Context) *ConsoleHandlerOptions
GetConsoleHandlerOptionsFromContext retrieves the options from the context.
If the options are not set in the context, a set of default options is returned instead.
func (*ConsoleHandlerOptions) AddToContext ¶ added in v0.2.0
func (o *ConsoleHandlerOptions) AddToContext(ctx context.Context) context.Context
AddToContext adds the options to the given context and returns the new context.
type FailoverHandlerOptions ¶
type FailoverHandlerOptions struct { // ContinueOnError determines whether or not to continue if an error occurs running middleware. ContinueOnError bool }
FailoverHandlerOptions holds the options available when creating the failoverHandler object.
func DefaultFailoverHandlerOptions ¶ added in v0.2.0
func DefaultFailoverHandlerOptions() FailoverHandlerOptions
DefaultFailoverHandlerOptions returns a default set of options for the handler.
func FailoverHandlerOptionsFromContext ¶ added in v0.5.0
func FailoverHandlerOptionsFromContext(ctx context.Context) *FailoverHandlerOptions
FailoverHandlerOptionsFromContext retrieves the options from the context.
If the options are not set in the context, a set of default options is returned instead.
type FileHandlerOptions ¶
type FileHandlerOptions struct { // DirMode is the mode to use when creating directories. // // By default, directories will be created with mode 0755. DirMode fs.FileMode // Filename is the name of the log file to write to. // // This is a required option. Filename string // FileMode is the mode to use when creating log files. // // By default, files will be created with mode 0640. FileMode fs.FileMode // Level is the minimum log level to write to the handler. // // If this is nil, it defaults to slogx.LevelInfo. Level *slogx.LevelVar // MaxFileCount indicates the maximum number of log files to keep, including the active log file. // // By default, this is set to 5. If this value is negative, an unlimited number of files will be kept. MaxFileCount int // MaxFileSize indicates the maximum size of any log file, in bytes. Once a file reaches this size, // it will be rotated automatically. // // By default, the maximum file size will be 10MB (10000000 bytes). If this value is negative, the file will // never be rotated. MaxFileSize int64 // RecordFormatter specifies the formatter to use to format the record before sending it to Slack. // // If no formatter is supplied, formatter.DefaultJSONFormatter is used to format the output. RecordFormatter formatter.BufferFormatter }
FileHandlerOptions holds options for the file handler.
func DefaultFileHandlerOptions ¶ added in v0.2.0
func DefaultFileHandlerOptions() FileHandlerOptions
DefaultFileHandlerOptions returns a default set of options for the handler.
func FileHandlerOptionsFromContext ¶ added in v0.5.0
func FileHandlerOptionsFromContext(ctx context.Context) *FileHandlerOptions
FileHandlerOptionsFromContext retrieves the options from the context.
If the options are not set in the context, a set of default options is returned instead.
type HTTPHandlerOptions ¶ added in v0.6.0
type HTTPHandlerOptions struct { // ContentType is the mime type to pass to the HTTP endpoint. // // By default, this is set to application/json as it is assumed the message being sent will be in JSON format. ContentType string // EnableAsync will execute the Handle() function in a separate goroutine. // // When async is enabled, you should be sure to call the Shutdown() function or use the slogx.Shutdown() // function to ensure all goroutines are finished and any pending records have been written. EnableAsync bool // HTTPClient allows for the use of a custom HTTP client for posting the message to the HTTP listener. // // If nil, a default resty client is used. HTTPClient *resty.Client // Level is the minimum log level to write to the handler. // // If this is nil, it defaults to slogx.LevelInfo. Level *slogx.LevelVar // RecordFormatter specifies the formatter to use to format the record before sending it to the HTTP listener. // // If no formatter is supplied, formatter.DefaultJSONFormatter is used to format the output. RecordFormatter formatter.BufferFormatter // URL is the URL of the HTTP endpoint to post the message to. // // This is a required option. URL string }
HTTPHandlerOptions holds the options for the HTTP handler.
func DefaultHTTPHandlerOptions ¶ added in v0.6.0
func DefaultHTTPHandlerOptions() HTTPHandlerOptions
DefaultHTTPHandlerOptions returns a default set of options for the handler.
func GetHTTPHandlerOptionsFromContext ¶ added in v0.6.0
func GetHTTPHandlerOptionsFromContext(ctx context.Context) *HTTPHandlerOptions
GetHTTPHandlerOptionsFromContext retrieves the options from the context.
If the options are not set in the context, a set of default options is returned instead.
func (*HTTPHandlerOptions) AddToContext ¶ added in v0.6.0
func (o *HTTPHandlerOptions) AddToContext(ctx context.Context) context.Context
AddToContext adds the options to the given context and returns the new context.
type JSONHandlerOptions ¶
type JSONHandlerOptions struct { // Level is the minimum log level to write to the handler. // // If this is nil, it defaults to slogx.LevelInfo. Level *slogx.LevelVar // RecordFormatter specifies the formatter to use to format the record before writing it to the writer. // // If no formatter is supplied, formatter.DefaultJSONFormatter is used to format the output. RecordFormatter formatter.BufferFormatter // Writer is where to write the output to. // // By default, messages are written to os.Stdout if not supplied. Writer io.Writer }
JSONHandlerOptions holds the options for the JSON handler.
func DefaultJSONHandlerOptions ¶ added in v0.2.0
func DefaultJSONHandlerOptions() JSONHandlerOptions
DefaultJSONHandlerOptions returns a default set of options for the handler.
func GetJSONHandlerOptionsFromContext ¶ added in v0.2.0
func GetJSONHandlerOptionsFromContext(ctx context.Context) *JSONHandlerOptions
GetJSONHandlerOptionsFromContext retrieves the options from the context.
If the options are not set in the context, a set of default options is returned instead.
func (*JSONHandlerOptions) AddToContext ¶ added in v0.2.0
func (o *JSONHandlerOptions) AddToContext(ctx context.Context) context.Context
AddToContext adds the options to the given context and returns the new context.
type MultiHandlerOptions ¶
type MultiHandlerOptions struct { // ContinueOnError determines whether or not to continue logging to handlers to if an error occurs while writing to // a particular handler or running any middleware. ContinueOnError bool // EnableAsync will execute the Handle() function in a separate goroutine in case there are slow handlers being // used for writing the record. // // Typically, a specific handler should implement its own async writing if it is slow, but this is a fallback in // case it does not. // // When async is enabled, you should be sure to call the Shutdown() function or use the slogx.Shutdown() // function to ensure all goroutines are finished and any pending records have been written. EnableAsync bool }
MultiHandlerOptions holds the options available when creating the multiHandler object.
func DefaultMultiHandlerOptions ¶ added in v0.2.0
func DefaultMultiHandlerOptions() MultiHandlerOptions
DefaultMultiHandlerOptions returns a default set of options for the handler.
func MultiHandlerOptionsFromContext ¶ added in v0.5.0
func MultiHandlerOptionsFromContext(ctx context.Context) *MultiHandlerOptions
MultiHandlerOptionsFromContext retrieves the options from the context.
If the options are not set in the context, a set of default options is returned instead.
type PipeHandlerFn ¶
PipeHandlerFn should take the clone of the given record, modify it as needed and return the modified version.
type PipeHandlerOptions ¶
type PipeHandlerOptions struct { // ContinueOnError determines whether or not to continue logging to handlers to if an error occurs while running any // of the pipe functions. ContinueOnError bool // PipeFns defines the list of functions to pipe the record through before passing it onto the next handler. PipeFns []PipeHandlerFn }
PipeHandlerOptions holds the options for the pipe handler.
func DefaultPipeHandlerOptions ¶ added in v0.2.0
func DefaultPipeHandlerOptions() PipeHandlerOptions
DefaultPipeHandlerOptions returns a default set of options for the handler.
func PipeHandlerOptionsFromContext ¶ added in v0.5.0
func PipeHandlerOptionsFromContext(ctx context.Context) *PipeHandlerOptions
PipeHandlerOptionsFromContext retrieves the options from the context.
If the options are not set in the context, a set of default options is returned instead.
type RoundRobinHandlerOptions ¶
type RoundRobinHandlerOptions struct { // ContinueOnError determines whether or not to continue if an error occurs running middleware. ContinueOnError bool }
RoundRobinHandlerOptions holds the options available when creating the roundRobinHandler object.
func DefaultRoundRobinHandlerOptions ¶ added in v0.2.0
func DefaultRoundRobinHandlerOptions() RoundRobinHandlerOptions
DefaultRoundRobinHandlerOptions returns a default set of options for the handler.
func RoundRobinHandlerOptionsFromContext ¶ added in v0.5.0
func RoundRobinHandlerOptionsFromContext(ctx context.Context) *RoundRobinHandlerOptions
RoundRobinHandlerOptionsFromContext retrieves the options from the context.
If the options are not set in the context, a set of default options is returned instead.