Documentation ¶
Overview ¶
Package apexovernsq provides a handler for github.com/apex/log. It's intended to act as a transport to allow log.Entry structs to pass through nsq and be reconstructed and passed to another handler on the other side.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewApexLogServiceContext ¶
Create a new logging context with service information.
Types ¶
type ApexLogNSQHandler ¶
type ApexLogNSQHandler struct {
// contains filtered or unexported fields
}
ApexLogNSQHandler is a handler that can be passed to github.com/apex/log.SetHandler.
func NewApexLogNSQHandler ¶
func NewApexLogNSQHandler(marshalFunc MarshalFunc, publishFunc PublishFunc, topic string) *ApexLogNSQHandler
NewApexLogNSQHandler returns a pointer to an apexovernsq.ApexLogNSQHandler that can in turn be passed to github.com/apex/log.SetHandler.
The marshalFunc provided will be used to marshal a github.com/apex/log.Entry as the body of a message sent over nsq.
The publishFunc is used to push a message onto the nsq. For simple cases, with only one nsq endpoint using github.com/nsqio/go-nsq.Producer.Publish is fine. For cases with multiple producers you'll want to wrap it. See the examples directory for an implementation of this.
The topic is a string determining the nsq topic the messages will be published to.
func (*ApexLogNSQHandler) HandleLog ¶
func (h *ApexLogNSQHandler) HandleLog(e *log.Entry) error
HandleLog makes ApexLogNSQHandler fulfil the interface required by github.com/apex/log for handlers. Each individual log entry made in client programs will eventually invoke this function when using this ApexLogNSQHandler.
type AsyncApexLogNSQHandler ¶
type AsyncApexLogNSQHandler struct {
// contains filtered or unexported fields
}
AsyncApexLogNSQHandler is a handler that can be passed to github.com/apex/log.SetHandler and will publish log entries on NSQ asynchronously.
func NewAsyncApexLogNSQHandler ¶
func NewAsyncApexLogNSQHandler(marshalFunc MarshalFunc, publishFunc PublishFunc, topic string, bufferSize int) *AsyncApexLogNSQHandler
NewAsyncApexLogNSQHandler returns a pointer to an apexovernsq.AsyncApexLogNSQHandler that can in turn be passed to github.com/apex/log.SetHandler. The AsyncApexLogNSQHandler uses a goroutine and a channel to make the publication of NSQ message asynchronous to the act of logging.
The marshalFunc provided will be used to marshal a github.com/apex/log.Entry as the body of a message sent over nsq.
The publishFunc is used to push a message onto the nsq. For simple cases, with only one nsq endpoint using github.com/nsqio/go-nsq.Producer.Publish is fine. For cases with multiple producers you'll want to wrap it. See the examples directory for an implementation of this.
The topic is a string determining the nsq topic the messages will be published to.
func (*AsyncApexLogNSQHandler) HandleLog ¶
func (h *AsyncApexLogNSQHandler) HandleLog(e *log.Entry) error
func (*AsyncApexLogNSQHandler) Stop ¶
func (h *AsyncApexLogNSQHandler) Stop()
type MarshalFunc ¶
MarshalFunc is a function signature for any function that can marshal an arbitrary struct to a slice of bytes.
type NSQApexLogHandler ¶
type NSQApexLogHandler struct {
// contains filtered or unexported fields
}
NSQApexLogHandler is a handler for NSQ that can consume messages who's Body is a marshalled github.com/apex/log.Entry.
func NewNSQApexLogHandler ¶
func NewNSQApexLogHandler(handler alog.Handler, unmarshalFunc UnmarshalFunc) *NSQApexLogHandler
NewNSQApexLogHandler creates a new NSQApexLogHandler with a provided github.com/apex/log.Handler and any function that satifies the UnmarshalFunc interface.
The provided UnmarshalFunc will be used to unmarshal the github.com/apex/log.Entry from the NSQ Message.Body field. It should match the marshal function used to publish the Message on the NSQ channel. If you don't have any special requirement using the Marshal and Unmarshal functions from code.avct.io/apexovernsq/protobuf should work well.
When the handler is invoked to consume a message, the provided github.com/apex/log.Handler will have it's HandleLog method called with the unmarshalled github.com/apex/log.Entry just as it would if you made a logging call locally.
func (*NSQApexLogHandler) HandleMessage ¶
func (alh *NSQApexLogHandler) HandleMessage(m *nsq.Message) error
HandleMessage makes NSQApexLogHandler implement the github.com/nsqio/go-nsq.Handler interface and therefore, NSQApexLogHandler can be passed to the AddHandler function of a github.com/nsqio/go-nsq.Consumer.
HandleMessage will unmarshal a github.com/apex/log.Entry from a github.com/nsqio/go-nsq.Message's Body and pass it into the github.com/apex/log.Handler provided when calling NewNSQApexLogHandler to construct the NSQApexLogHandler.
type PublishFunc ¶
PublishFunc is a function signature for any function that publishes a message on a provided nsq topic. Typically this is github.com/nsqio/go-nsq.Producer.Publish, or something that wraps it.
type ServiceFilterApexLogHandler ¶
type ServiceFilterApexLogHandler struct {
// contains filtered or unexported fields
}
func NewApexLogServiceFilterHandler ¶
func NewApexLogServiceFilterHandler(handler log.Handler, filter *[]string) *ServiceFilterApexLogHandler
type UnmarshalFunc ¶
UnmarshalFunc is a function signature for any function that can unmarshal an arbitrary struct from a slice of bytes. Whilst we only ever want to support github.com/apex/log.Entry structs, we support this interface because it allows using 3rd party Marshal/Unmarshal functions simply.
Directories ¶
Path | Synopsis |
---|---|
apps
|
|
example
|
|
log-to-nsq
log_to_nsq is an example program that demonstrates the use of apexovernsq.
|
log_to_nsq is an example program that demonstrates the use of apexovernsq. |
Package protobuf is a generated protocol buffer package.
|
Package protobuf is a generated protocol buffer package. |