Documentation ¶
Index ¶
- Variables
- func Debug(format string, args ...interface{})
- func IsInterruption(err error) bool
- func IsSignal(err error, signals ...os.Signal) bool
- func IsTerminal(fd int) bool
- func IsTermination(err error) bool
- func Log(format string, args ...interface{})
- func Signal(sigchan <-chan os.Signal) <-chan os.Signal
- func SignalWith(handler Handler, sigchan <-chan os.Signal) <-chan os.Signal
- func SortArgs(args Args)
- func SourceForPC(pc uintptr) (file string, line int)
- func WithSignals(ctx context.Context, signals ...os.Signal) (context.Context, context.CancelFunc)
- type Arg
- type Args
- type Event
- type Handler
- type HandlerFunc
- type Logger
- type SignalError
Constants ¶
This section is empty.
Variables ¶
var DefaultLogger = NewLogger(nil)
DefaultLogger is the default logger used by the Log function. This may be overwritten by the program to change the default route for log events.
Functions ¶
func Debug ¶
func Debug(format string, args ...interface{})
Debug emits a debug event to the default logger.
func IsInterruption ¶
IsInterruption returns true if the given error was caused by receiving an interruption signal.
func IsSignal ¶
IsSignal returns true if the given error is a *SignalError that was generated upon receipt of one of the given signals. If no signal is passed, the function only tests for err to be of type *SginalError.
func IsTerminal ¶
IsTerminal returns true if the given file descriptor is a terminal.
func IsTermination ¶
IsTermination returns true if the given error was caused by receiving a termination signal.
func Log ¶
func Log(format string, args ...interface{})
Log emits a log event to the default logger.
func Signal ¶
Signal triggers events on the default handler for every signal that arrives on sigchan. The function returns a channel on which signals are forwarded, the program should use this channel instead of sigchan to receive signals.
func SignalWith ¶
SignalWith triggers events on handler for every signal that arrives on sigchan. The function returns a channel on which signals are forwarded, the program should use this channel instead of sigchan to receive signals.
func SortArgs ¶
func SortArgs(args Args)
SortArgs sorts a list of argument by their argument names.
This is not a stable sorting operation, elements with equal values may not be in the same order they were originally after the function returns.
func SourceForPC ¶
SourceForPC returns the file and line given a program counter address. The file path is in the canonical form for Go programs, starting with the package path.
func WithSignals ¶
WithSignals returns a copy of the given context which may be canceled if any of the given signals is received by the program.
Types ¶
type Arg ¶
type Arg struct { Name string Value interface{} }
Arg represents a single event argument.
type Args ¶
type Args []Arg
Args reprsents a list of event arguments.
type Event ¶
type Event struct { // Message carries information about the event in a human-readable format. Message string // Source represents the location where this event was generated from. Source string // Args is the list of arguments of the event, it is intended to give // context about the information carried by the even in a format that can // be processed by a program. Args Args // Time is the time at which the event was generated. Time time.Time // Debug is set to true if this is a debugging event. Debug bool }
The Event type represents unique events generated by the program. They carry context about how they were triggered and information to pass to handlers.
type Handler ¶
type Handler interface { // HandleEvent is called by event producers on their event handler, passing // one event object as argument to the function. // // The handler MUST NOT retain any references to the event or its fields. If // the handler needs to capture the event is has to create a copy by calling // e.Clone. HandleEvent(e *Event) }
The Handler interface is implemented by types that intend to be event routers or apply transformations to an event before forwarding it to another handler.
var ( // Discard is a handler that does nothing with the events it receives. Discard Handler = HandlerFunc(func(e *Event) {}) // DefaultHandler is the default handler used when non is specified. DefaultHandler Handler = Discard )
func MultiHandler ¶
MultiHandler returns a new Handler which broadcasts the events it receives to its list of handlers.
type HandlerFunc ¶
type HandlerFunc func(*Event)
HandlerFunc makes it possible for simple function types to be used as event handlers.
type Logger ¶
type Logger struct { // Handler is the event handler receiving events from the logger. Handler Handler // Args is a list of arguments that get automatically injected into every // events produced by the logger. Args Args // CallDepth is used to adjust which caller the logger should report its // events are coming from. // Leaving to zero means reporting the direct caller of the logger's // methods. CallDepth int // EnableSource controls whether the logger should report the program counter // address of its caller on the events it produces. // This has a significant impact on the performance of the logger's Log and // Debug method but also provides very important insights, be mindful about // turning it on or off. EnableSource bool // EnableDebug controls whether calls to Debug produces events. EnableDebug bool }
A Logger is a wrapper around an event handler which exposes a Log method for formatting event messages before sending them to the handler.
The format supported by the Log method is a superset of the fmt-style format, where the 'verbs' may include a column-surrounded value representing the name of the matching argument.
The Log method also makes a special case when it gets an events.Args as last argument, it doesn't use it to format the message and instead simply append it to the event's argument list.
Here's an example with the defalut logger:
events.Log("Hello %{name}s!", "Luke", events.Args{ {"from", "Han"}, })
Which produces an event that looks like this:
events.Event{ Message: "Hello Luke!", Args: events.Args{{"name", "Luke"}, {"from", "Han"}}, ... }
Logger instances are safe to use concurrently from multiple goroutines.
func (*Logger) Debug ¶
Debug is like Log but only produces events if the logger has debugging enabled.
type SignalError ¶
SignalError is a wrapper for the os.Signal type which also implements the error interface so it can be reported by the Err method of a context.
func (*SignalError) Error ¶
func (s *SignalError) Error() string
Error satisfies the error interface.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package ecslogs provides the implementation of an event handler that outputs events in a ecslogs-compatible format.
|
Package ecslogs provides the implementation of an event handler that outputs events in a ecslogs-compatible format. |
Package log provides the implementation of a shim between the standard log package and event handlers.
|
Package log provides the implementation of a shim between the standard log package and event handlers. |
Package sigevents installs signal handlers for SIGUSR1 and SIGUSR2, enabling debug logs when the former is received, or disabling them on the latter.
|
Package sigevents installs signal handlers for SIGUSR1 and SIGUSR2, enabling debug logs when the former is received, or disabling them on the latter. |
Package text provides the implementation of an event handler that outputs events in a human-readable format.
|
Package text provides the implementation of an event handler that outputs events in a human-readable format. |