Documentation ¶
Overview ¶
package message defines the Composer interface and a handful of implementations which represent the structure for messages produced by grip.
Message Composers ¶
The Composer interface provides a common way to define messages, with two main goals:
1. Provide a common interface for representing structured and unstructured logging data regardless of logging backend or interface.
2. Provide a method for *lazy* construction of log messages so they're built *only* if a log message is over threshold.
The message package also contains many implementations of Composer which should support most logging use cases. However, any package using grip for logging may need to implement custom composer types.
The Composer implementations in the message package compose the Base type to provide some common functionality around priority setting and data collection.
The logging methods in the Journaler interface typically convert all inputs into a reasonable Composer implementations.
Error Messages ¶
The error message composers underpin the Catch<> logging messages, which allow you to log error messages but let the logging system elide logging for nil errors.
Functional Messages ¶
Grip can automatically convert three types of functions into messages:
func() Fields func() Composer func() error
The benefit of these functions is that they're only called if the message is above the logging threshold. In the case of conditional logging (i.e. When), if the conditional is false, then the function is never called.
in the case of all the buffered sending implementation, the function call can be deferred and run outside of the main thread, and so may be an easy way to defer message production outside in cases where messages may be complicated.
Additionally, the message conversion in grip's logging method can take these function types and convert them to these messages, which can clean up some call-site operations, and makes it possible to use defer with io.Closer methods without wrapping the method in an additional function, as in:
defer grip.Error(file.Close)
Although the WrapErrorFunc method, as in the following may permit useful annotation, as follows, which has the same "lazy" semantics.
defer grip.Error(message.WrapErrorFunc(file.Close, message.Fields{}))
Bytes Messages ¶
The bytes types make it possible to send a byte slice as a message.
Stack Messages ¶
The Stack message Composer implementations capture a full stacktrace information during message construction, and attach a message to that trace. The string form of the message includes the package and file name and line number of the last call site, while the Raw form of the message includes the entire stack. Use with an appropriate sender to capture the desired output.
All stack message constructors take a "skip" parameter which tells how many stack frames to skip relative to the invocation of the constructor. Skip values less than or equal to 0 become 1, and are equal the call site of the constructor, use larger numbers if you're wrapping these constructors in our own infrastructure.
In general Composers are lazy, and defer work until the message is being sent; however, the stack Composers must capture the stack when they're called rather than when they're sent to produce meaningful data.
Index ¶
- Constants
- func GetDefaultFieldsMessage(msg Composer, val string) string
- func IsStructured(msg Composer) bool
- type Base
- type Composer
- func CollectAllProcesses() []Composer
- func CollectBasicGoStats() Composer
- func CollectGoStatsDeltas() Composer
- func CollectGoStatsRates() Composer
- func CollectGoStatsTotals() Composer
- func CollectProcessInfo(pid int32) Composer
- func CollectProcessInfoSelf() Composer
- func CollectProcessInfoSelfWithChildren() []Composer
- func CollectProcessInfoWithChildren(pid int32) []Composer
- func CollectSystemInfo() Composer
- func ConvertToComposer(p level.Priority, message interface{}) Composer
- func ConvertToComposerWithLevel(p level.Priority, message interface{}) Composer
- func MakeComposerProducerMessage(cp ComposerProducer) Composer
- func MakeConvertedFieldsProducer(mp func() map[string]interface{}) Composer
- func MakeEmailMessage(e Email) Composer
- func MakeErrorProducerMessage(ep ErrorProducer) Composer
- func MakeFields(f Fields) Composer
- func MakeFieldsMessage(message string, f Fields) Composer
- func MakeFieldsProducerMessage(fp FieldsProducer) Composer
- func MakeGoStatsDeltas(msg string) Composer
- func MakeGoStatsRates(msg string) Composer
- func MakeGoStatsTotals(msg string) Composer
- func MakeGroupComposer(msgs ...Composer) Composer
- func MakeSimpleFields(f Fields) Composer
- func MakeSimpleFieldsMessage(msg string, f Fields) Composer
- func MakeSlackMessage(target string, msg string, attachments []SlackAttachment) Composer
- func MakeSystemInfo(message string) Composer
- func NewBytes(b []byte) Composer
- func NewBytesMessage(p level.Priority, b []byte) Composer
- func NewComposerProducerMessage(p level.Priority, cp ComposerProducer) Composer
- func NewConvertedFieldsProducer(p level.Priority, mp func() map[string]interface{}) Composer
- func NewDefaultMessage(p level.Priority, message string) Composer
- func NewEmailMessage(l level.Priority, e Email) Composer
- func NewError(err error) Composer
- func NewErrorMessage(p level.Priority, err error) Composer
- func NewErrorProducerMessage(p level.Priority, ep ErrorProducer) Composer
- func NewErrorWrap(err error, base string, args ...interface{}) Composer
- func NewErrorWrapMessage(p level.Priority, err error, base string, args ...interface{}) Composer
- func NewErrorWrappedComposer(err error, m Composer) Composer
- func NewFields(p level.Priority, f Fields) Composer
- func NewFieldsMessage(p level.Priority, message string, f Fields) Composer
- func NewFieldsProducerMessage(p level.Priority, fp FieldsProducer) Composer
- func NewFormatted(base string, args ...interface{}) Composer
- func NewFormattedMessage(p level.Priority, base string, args ...interface{}) Composer
- func NewGoStatsDeltas(p level.Priority, msg string) Composer
- func NewGoStatsRates(p level.Priority, msg string) Composer
- func NewGoStatsTotals(p level.Priority, msg string) Composer
- func NewGroupComposer(msgs []Composer) Composer
- func NewGroupComposerWithPriority(p level.Priority, msgs []Composer) Composer
- func NewLine(args ...interface{}) Composer
- func NewLineMessage(p level.Priority, args ...interface{}) Composer
- func NewProcessInfo(priority level.Priority, pid int32, message string) Composer
- func NewSimpleBytes(b []byte) Composer
- func NewSimpleBytesMessage(p level.Priority, b []byte) Composer
- func NewSimpleFields(p level.Priority, f Fields) Composer
- func NewSimpleFieldsMessage(p level.Priority, msg string, f Fields) Composer
- func NewSimpleString(m string) Composer
- func NewSimpleStringMessage(p level.Priority, message string) Composer
- func NewSlackMessage(p level.Priority, target string, msg string, attachments []SlackAttachment) Composer
- func NewStack(skip int, message string) Composer
- func NewStackFormatted(skip int, message string, args ...interface{}) Composer
- func NewStackLines(skip int, messages ...interface{}) Composer
- func NewString(m string) Composer
- func NewSystemInfo(priority level.Priority, message string) Composer
- func When(cond bool, m interface{}) Composer
- func WhenMsg(cond bool, m string) Composer
- func Whenf(cond bool, m string, args ...interface{}) Composer
- func Whenln(cond bool, args ...interface{}) Composer
- func WrapError(err error, m interface{}) Composer
- func WrapErrorFunc(ep ErrorProducer, m interface{}) Composer
- func WrapErrorf(err error, msg string, args ...interface{}) Composer
- func WrapStack(skip int, msg interface{}) Composer
- type ComposerProducer
- type Email
- type ErrorProducer
- type Fields
- type FieldsProducer
- type GoRuntimeInfo
- type GroupComposer
- func (g *GroupComposer) Add(msg Composer)
- func (g *GroupComposer) Annotate(k string, v interface{}) error
- func (g *GroupComposer) Append(msgs ...Composer)
- func (g *GroupComposer) Extend(msg []Composer)
- func (g *GroupComposer) Loggable() bool
- func (g *GroupComposer) Messages() []Composer
- func (g *GroupComposer) Priority() level.Priority
- func (g *GroupComposer) Raw() interface{}
- func (g *GroupComposer) SetPriority(l level.Priority) error
- func (g *GroupComposer) String() string
- type ProcessInfo
- type Slack
- type SlackAttachment
- type SlackAttachmentField
- type StackFrame
- type StackFrames
- type StackTrace
- type StatCPUTimes
- type SystemInfo
Constants ¶
const FieldsMsgName = "message"
FieldsMsgName is the name of the default "message" field in the fields structure.
Variables ¶
This section is empty.
Functions ¶
func GetDefaultFieldsMessage ¶
GetDefaultFieldsMessage returns a "short" message form, to avoid needing to call .String() on the type, which produces a string form of the message. If the message has a short form (either in the map, or separate), it's returned, otherwise the "val" is returned.
For composers not that don't wrap Fields, this function will always return the input value.
func IsStructured ¶
IsStructured returns false if the Composer has a string form which is merely a representation of the structured form.
Additionally, returns true for all unknown types, including all types not produced by this package.
Types ¶
type Base ¶
type Base struct { Level level.Priority `bson:"level,omitempty" json:"level,omitempty" yaml:"level,omitempty"` Hostname string `bson:"hostname,omitempty" json:"hostname,omitempty" yaml:"hostname,omitempty"` Time time.Time `bson:"time,omitempty" json:"time,omitempty" yaml:"time,omitempty"` Process string `bson:"process,omitempty" json:"process,omitempty" yaml:"process,omitempty"` Pid int `bson:"pid,omitempty" json:"pid,omitempty" yaml:"pid,omitempty"` Context Fields `bson:"context,omitempty" json:"context,omitempty" yaml:"context,omitempty"` }
Base provides a simple embedable implementation of some common aspects of a message.Composer. Additionally the Collect() method collects some simple metadata, that may be useful for some more structured logging applications.
func (*Base) Annotate ¶
Annotate makes it possible for callers and senders to add structured data to a message. This may be overridden for some implementations
func (*Base) Collect ¶
Collect records the time, process name, and hostname. Useful in the context of a Raw() method.
func (*Base) IsZero ¶
IsZero returns true when Base is nil or it is non-nil and none of its fields are set.
type Composer ¶
type Composer interface { // Returns the content of the message as a string for use in // line-printing logging engines. String() string // A "raw" format of the logging output for use by some Sender // implementations that write logged items to interfaces that // accept JSON or another structured format. Raw() interface{} // Returns "true" when the message has content and should be // logged, and false otherwise. When false, the sender can // (and should!) ignore messages even if they are otherwise // above the logging threshold. Loggable() bool // Annotate makes it possible for Senders and Journalers to // add structured data to a log message. May return an error // when the key alrady exists. Annotate(string, interface{}) error // Priority returns the priority of the message. Priority() level.Priority SetPriority(level.Priority) error }
Composer defines an interface with a "String()" method that returns the message in string format. Objects that implement this interface, in combination to the Compose[*] operations, the String() method is only caled if the priority of the method is greater than the threshold priority. This makes it possible to defer building log messages (that may be somewhat expensive to generate) until it's certain that we're going to be outputting the message.
func CollectAllProcesses ¶
func CollectAllProcesses() []Composer
CollectAllProcesses returns a slice of populated ProcessInfo message.Composer interfaces for all processes currently running on a system.
func CollectBasicGoStats ¶
func CollectBasicGoStats() Composer
CollectBasicGoStats returns some very basic runtime statistics about the current go process, using runtime.MemStats and runtime.NumGoroutine.
The data reported for the runtime event metrics (e.g. mallocs, frees, gcs, and cgo calls,) are the counts since the last time metrics were collected, and are reported as rates calculated since the last time the statics were collected.
Values are cached between calls, to produce the deltas. For the best results, collect these messages on a regular interval.
Internally, this uses message.Fields message type, which means the order of the fields when serialized is not defined and applications cannot manipulate the Raw value of this composer.
The basic idea is taken from https://github.com/YoSmudge/go-stats.
func CollectGoStatsDeltas ¶
func CollectGoStatsDeltas() Composer
CollectGoStatsDeltas constructs a Composer, which is a GoRuntimeInfo internally, that contains data collected from the Go runtime about the state of memory use and garbage collection.
The data reported for the runtime event metrics (e.g. mallocs, frees, gcs, and cgo calls,) are the counts since the last time metrics were collected.
Values are cached between calls, to produce the deltas. For the best results, collect these messages on a regular interval.
func CollectGoStatsRates ¶
func CollectGoStatsRates() Composer
CollectGoStatsRates constructs a Composer, which is a GoRuntimeInfo internally, that contains data collected from the Go runtime about the state of memory use and garbage collection.
The data reported for the runtime event metrics (e.g. mallocs, frees, gcs, and cgo calls,) are the counts since the last time metrics were collected, divided by the time since the last time the metric was collected, to produce a rate, which is calculated using integer division.
For the best results, collect these messages on a regular interval.
func CollectGoStatsTotals ¶
func CollectGoStatsTotals() Composer
CollectGoStatsTotals constructs a Composer, which is a GoRuntimeInfo internally, that contains data collected from the Go runtime about the state of memory use and garbage collection.
The data reported for the runtime event metrics (e.g. mallocs, frees, gcs, and cgo calls,) are totals collected since the beginning on the runtime.
func CollectProcessInfo ¶
CollectProcessInfo returns a populated ProcessInfo message.Composer instance for the specified pid.
func CollectProcessInfoSelf ¶
func CollectProcessInfoSelf() Composer
CollectProcessInfoSelf returns a populated ProcessInfo message.Composer for the pid of the current process.
func CollectProcessInfoSelfWithChildren ¶
func CollectProcessInfoSelfWithChildren() []Composer
CollectProcessInfoSelfWithChildren returns a slice of populated ProcessInfo message.Composer instances for the current process and all children processes.
func CollectProcessInfoWithChildren ¶
CollectProcessInfoWithChildren returns a slice of populated ProcessInfo message.Composer instances for the process with the specified pid and all children processes for that process.
func CollectSystemInfo ¶
func CollectSystemInfo() Composer
CollectSystemInfo returns a populated SystemInfo object, without a message.
func ConvertToComposer ¶
ConvertToComposer can coerce unknown objects into Composer instances, as possible. This method will override the priority of composers set to it.
func ConvertToComposerWithLevel ¶
ConvertToComposerWithLevel can coerce unknown objects into Composers, but will only override the priority of Composers.
func MakeComposerProducerMessage ¶
func MakeComposerProducerMessage(cp ComposerProducer) Composer
MakeComposerMessage constructs a message that will call the ComposerProducer function lazily during logging.
ComposerProducer functions are only called, before calling the Loggable, String, Raw, or Annotate methods. Changing the priority does not call the function. In practice, if the priority of the message is below the logging threshold, then the function will never be called.
func MakeConvertedFieldsProducer ¶
MakeConvertedFieldsProducer converts a generic map to a fields producer, as the message types are equivalent.
func MakeEmailMessage ¶
MakeEmailMessage creates a composer for emails without a priority set
func MakeErrorProducerMessage ¶
func MakeErrorProducerMessage(ep ErrorProducer) Composer
MakeErrorProducerMessage returns a mesage that wrapps an error producing function. If the function returns then there is never a message logged.
ErrorProducer functions are only called, before calling the Loggable, String, Raw, or Annotate methods. Changing the priority does not call the function. In practice, if the priority of the message is below the logging threshold, then the function will never be called.
func MakeFields ¶
MakeFields creates a composer interface from *just* a Fields instance.
func MakeFieldsMessage ¶
MakeFieldsMessage constructs a fields Composer from a message string and Fields object, without specifying the priority of the message.
func MakeFieldsProducerMessage ¶
func MakeFieldsProducerMessage(fp FieldsProducer) Composer
MakeFieldsProducerMessage constructs a lazy FieldsProducer wrapping message at the specified level.
FieldsProducer functions are only called, before calling the Loggable, String, Raw, or Annotate methods. Changing the priority does not call the function. In practice, if the priority of the message is below the logging threshold, then the function will never be called.
func MakeGoStatsDeltas ¶
MakeGoStatsDeltas has the same semantics as CollectGoStatsDeltas, but additionally allows you to set a message string to annotate the data.
func MakeGoStatsRates ¶
MakeGoStatsRates has the same semantics as CollectGoStatsRates, but additionally allows you to set a message string to annotate the data.
func MakeGoStatsTotals ¶
MakeGoStatsTotals has the same semantics as CollectGoStatsTotals, but additionally allows you to set a message string to annotate the data.
func MakeGroupComposer ¶
MakeGroupComposer provides a variadic interface for creating a GroupComposer.
func MakeSimpleFields ¶
MakeSimpleFields returns a structured Composer that does not attach basic logging metadata.
func MakeSimpleFieldsMessage ¶
MakeSimpleFieldsMessage returns a structured Composer that does not attach basic logging metadata, but allows callers to specify the message (the "message" field) as a string.
func MakeSlackMessage ¶
func MakeSlackMessage(target string, msg string, attachments []SlackAttachment) Composer
MakeSlackMessage creates a composer for message to slack without a priority
func MakeSystemInfo ¶
MakeSystemInfo builds a populated SystemInfo object with the specified message.
func NewBytesMessage ¶
NewBytesMessage provides a Composer interface around a byte slice, which are always logable unless the string is empty.
func NewComposerProducerMessage ¶
func NewComposerProducerMessage(p level.Priority, cp ComposerProducer) Composer
NewComposerMessage constructs a message, with the given priority, that will call the ComposerProducer function lazily during logging.
ComposerProducer functions are only called, before calling the Loggable, String, Raw, or Annotate methods. Changing the priority does not call the function. In practice, if the priority of the message is below the logging threshold, then the function will never be called.
func NewConvertedFieldsProducer ¶
NewConvertedFieldsProducer converts a generic map to a fields producer at the specified priority, as the message types are equivalent,
func NewDefaultMessage ¶
NewDefaultMessage provides a Composer interface around a single string, which are always logable unless the string is empty.
func NewEmailMessage ¶
NewEmailMessage returns a composer for emails
func NewError ¶
NewError returns an error composer, like NewErrorMessage, but without the requirement to specify priority, which you may wish to specify directly.
func NewErrorMessage ¶
NewErrorMessage takes an error object and returns a Composer instance that only renders a loggable message when the error is non-nil.
These composers also implement the error interface and the pkg/errors.Causer interface and so can be passed as errors and used with existing error-wrapping mechanisms.
func NewErrorProducerMessage ¶
func NewErrorProducerMessage(p level.Priority, ep ErrorProducer) Composer
NewErrorProducerMessage returns a mesage that wrapps an error producing function, at the specified level. If the function returns then there is never a message logged.
ErrorProducer functions are only called, before calling the Loggable, String, Raw, or Annotate methods. Changing the priority does not call the function. In practice, if the priority of the message is below the logging threshold, then the function will never be called.
func NewErrorWrap ¶
NewErrorWrap produces a message.Composer that combines the functionality of an Error composer that renders a loggable error message for non-nil errors with a normal formatted message (e.g. fmt.Sprintf). These messages only log if the error is non-nil.
func NewErrorWrapMessage ¶
NewErrorWrapMessage produces a fully configured message.Composer that combines the functionality of an Error composer that renders a loggable error message for non-nil errors with a normal formatted message (e.g. fmt.Sprintf). These messages only log if the error is non-nil.
func NewErrorWrappedComposer ¶
NewErrorWrappedComposer provvides a way to construct a log message that annotates an error.
func NewFieldsMessage ¶
NewFieldsMessage creates a fully configured Composer instance that will attach some additional structured data. This constructor allows you to include a string message as well as Fields object.
func NewFieldsProducerMessage ¶
func NewFieldsProducerMessage(p level.Priority, fp FieldsProducer) Composer
NewFieldsProducerMessage constructs a lazy FieldsProducer wrapping message at the specified level.
FieldsProducer functions are only called, before calling the Loggable, String, Raw, or Annotate methods. Changing the priority does not call the function. In practice, if the priority of the message is below the logging threshold, then the function will never be called.
func NewFormatted ¶
NewFormatted returns a message.Composer roughly equivalent to an fmt.Sprintf().
func NewFormattedMessage ¶
NewFormattedMessage takes arguments as fmt.Sprintf(), and returns an object that only runs the format operation as part of the String() method.
func NewGoStatsDeltas ¶
NewGoStatsDeltas has the same semantics as CollectGoStatsDeltas, but additionally allows you to set a message string to annotate the data.
func NewGoStatsRates ¶
NewGoStatsRates has the same semantics as CollectGoStatsRates, but additionally allows you to set a message string to annotate the data.
func NewGoStatsTotals ¶
NewGoStatsTotals has the same semantics as CollectGoStatsTotals, but additionally allows you to set a message string and log level to annotate the data.
func NewGroupComposer ¶
NewGroupComposer returns a GroupComposer object from a slice of Composers.
func NewGroupComposerWithPriority ¶
NewGroupComposerWithPriority constructs a group composer from a collection of composers.
func NewLine ¶
func NewLine(args ...interface{}) Composer
NewLine returns a message Composer roughly equivalent to fmt.Sprintln().
func NewLineMessage ¶
NewLineMessage is a basic constructor for a type that, given a bunch of arguments, calls fmt.Sprintln() on the arguments passed to the constructor during the String() operation. Use in combination with Compose[*] logging methods.
func NewProcessInfo ¶
NewProcessInfo constructs a fully configured and populated Processinfo message.Composer instance for the specified process.
func NewSimpleBytes ¶
NewSimpleBytes produces a bytes-wrapping message but does not collect metadata.
func NewSimpleBytesMessage ¶
NewSimpleBytesMessage produces a bytes-wrapping message with the specified priority but does not collect metadata.
func NewSimpleFields ¶
NewSimpleFields returns a structured Composer that does not attach basic logging metadata and allows callers to configure the messages' log level.
func NewSimpleFieldsMessage ¶
NewSimpleFieldsMessage returns a structured Composer that does not attach basic logging metadata, but allows callers to specify the message (the "message" field) as well as the message's log-level.
func NewSimpleString ¶
NewSimpleString produces a string message that does not attach process metadata.
func NewSimpleStringMessage ¶
NewSimpleStringMessage produces a string message with a priority that does not attach process metadata.
func NewSlackMessage ¶
func NewSlackMessage(p level.Priority, target string, msg string, attachments []SlackAttachment) Composer
NewSlackMessage creates a composer for messages to slack
func NewStack ¶
NewStack builds a Composer implementation that captures the current stack trace with a single string message. Use the skip argument to skip frames if your embedding this in your own wrapper or wrappers.
func NewStackFormatted ¶
NewStackFormatted returns a composer that builds a fmt.Printf style message that also captures a stack trace. Use the skip argument to skip frames if your embedding this in your own wrapper or wrappers.
func NewStackLines ¶
NewStackLines returns a composer that builds a fmt.Println style message that also captures a stack trace. Use the skip argument to skip frames if your embedding this in your own wrapper or wrappers.
func NewSystemInfo ¶
NewSystemInfo returns a fully configured and populated SystemInfo object.
func When ¶
When returns a conditional message that is only logged if the condition is bool. Converts the second argument to a composer, if needed, using the same rules that the logging methods use.
func WhenMsg ¶
WhenMsg returns a conditional message that is only logged if the condition is bool, and creates a string message that will only log when the message content is not the empty string. Use this for a more strongly-typed conditional logging message.
func Whenf ¶
Whenf returns a conditional message that is only logged if the condition is bool, and creates a sprintf-style message, which will itself only log if the base expression is not the empty string.
func Whenln ¶
Whenln returns a conditional message that is only logged if the condition is bool, and creates a sprintf-style message, which will itself only log if the base expression is not the empty string.
func WrapError ¶
WrapError wraps an error and creates a composer converting the argument into a composer in the same manner as the front end logging methods.
func WrapErrorFunc ¶
func WrapErrorFunc(ep ErrorProducer, m interface{}) Composer
WrapErrorFunc produces a lazily-composed wrapped error message. The function is only called is
The resulting method itself implements the "error" interface (supporing unwrapping,) as well as the composer type, so you can return the result of this function as an error to avoid needing to manage multiple error annotations.
func WrapErrorf ¶
WrapErrorf wraps an error and creates a composer using a Sprintf-style formated composer.
type ComposerProducer ¶
type ComposerProducer func() Composer
ComposerProducer constructs a lazy composer, and makes it easy to implement new Composers as functions returning an existing composer type. Consider the following:
grip.Info(func() message.Composer { return WrapError(validateRequest(req), message.Fields{"op": "name"})})
Grip can automatically convert these functions when passed to a logging function.
If the Fields object is nil or empty then no message is ever logged.
type Email ¶
type Email struct { From string `bson:"from" json:"from" yaml:"from"` Recipients []string `bson:"recipients" json:"recipients" yaml:"recipients"` Subject string `bson:"subject" json:"subject" yaml:"subject"` Body string `bson:"body" json:"body" yaml:"body"` // PlainTextContents dictates the Content-Type of the email. If true, // it will text/plain; otherwise, it is text/html. This value is overridden // by the presence of a "Content-Type" header in Headers. PlainTextContents bool `bson:"is_plain_text" json:"is_plain_text" yaml:"is_plain_text"` // Headers adds additional headers to the email body, ignoring any // named "To", "From", "Subject", or "Content-Transfer-Encoding" // (which should be set with the above fields) Headers map[string][]string `bson:"headers" json:"headers" yaml:"headers"` }
Email represents the parameters of an email message
type ErrorProducer ¶
type ErrorProducer func() error
ErrorProducer is a function that returns an error, and is used for constructing message that lazily wraps the resulting function which is called when the message is dispatched.
If you pass one of these functions to a logging method, the ConvertToComposer operation will construct a lazy Composer based on this function, as in:
grip.Error(func() error { return errors.New("error message") })
It may be useful also to pass a "closer" function in this form, as in:
grip.Error(file.Close)
As a special case the WrapErrorFunc method has the same semantics as other ErrorProducer methods, but makes it possible to annotate an error.
type Fields ¶
type Fields map[string]interface{}
Fields is a convince type that wraps map[string]interface{} and is used for attaching structured metadata to a build request. For example:
message.Fields{"key0", <value>, "key1", <value>}
type FieldsProducer ¶
type FieldsProducer func() Fields
FieldsProducer is a function that returns a structured message body as a way of writing simple Composer implementations in the form anonymous functions, as in:
grip.Info(func() message.Fields {return message.Fields{"message": "hello world!"}})
Grip can automatically convert these functions when passed to a logging function.
If the Fields object is nil or empty then no message is logged.
type GoRuntimeInfo ¶
type GoRuntimeInfo struct { HeapObjects uint64 `bson:"memory.objects.heap" json:"memory.objects.heap" yaml:"memory.objects.heap"` Alloc uint64 `bson:"memory.summary.alloc" json:"memory.summary.alloc" yaml:"memory.summary.alloc"` HeapSystem uint64 `bson:"memory.summary.system" json:"memory.summary.system" yaml:"memory.summary.system"` HeapIdle uint64 `bson:"memory.heap.idle" json:"memory.heap.idle" yaml:"memory.heap.idle"` HeapInUse uint64 `bson:"memory.heap.used" json:"memory.heap.used" yaml:"memory.heap.used"` Mallocs int64 `bson:"memory.counters.mallocs" json:"memory.counters.mallocs" yaml:"memory.counters.mallocs"` Frees int64 `bson:"memory.counters.frees" json:"memory.counters.frees" yaml:"memory.counters.frees"` GC int64 `bson:"gc.rate" json:"gc.rate" yaml:"gc.rate"` GCPause time.Duration `bson:"gc.pause.duration.last" json:"gc.pause.last" yaml:"gc.pause.last"` GCLatency time.Duration `bson:"gc.pause.duration.latency" json:"gc.pause.duration.latency" yaml:"gc.pause.duration.latency"` Goroutines int64 `bson:"goroutines.total" json:"goroutines.total" yaml:"goroutines.total"` CgoCalls int64 `bson:"cgo.calls" json:"cgo.calls" yaml:"cgo.calls"` Message string `bson:"message" json:"message" yaml:"message"` Base `json:"metadata,omitempty" bson:"metadata,omitempty" yaml:"metadata,omitempty"` // contains filtered or unexported fields }
GoRuntimeInfo provides
func (*GoRuntimeInfo) Loggable ¶
func (s *GoRuntimeInfo) Loggable() bool
Loggable returns true when the GoRuntimeInfo structure is populated. Loggable is part of the Composer interface.
func (*GoRuntimeInfo) Raw ¶
func (s *GoRuntimeInfo) Raw() interface{}
Raw is part of the Composer interface and returns the GoRuntimeInfo object itself.
func (*GoRuntimeInfo) String ¶
func (s *GoRuntimeInfo) String() string
type GroupComposer ¶
type GroupComposer struct {
// contains filtered or unexported fields
}
GroupComposer handles groups of composers as a single message, joining messages with a new line for the string format and returning a slice of interfaces for the Raw() form.
Unlike most composer types, the GroupComposer is exported, and provides the additional Messages() method to access the composer objects as a slice.
func (*GroupComposer) Add ¶
func (g *GroupComposer) Add(msg Composer)
Add supports adding messages to an existing group composer.
func (*GroupComposer) Annotate ¶
func (g *GroupComposer) Annotate(k string, v interface{}) error
Annotate calls the Annotate method of every non-nil component Composer.
func (*GroupComposer) Append ¶
func (g *GroupComposer) Append(msgs ...Composer)
Append provides a variadic alternative to the Extend method.
func (*GroupComposer) Extend ¶
func (g *GroupComposer) Extend(msg []Composer)
Extend makes it possible to add a group of messages to an existing group composer.
func (*GroupComposer) Loggable ¶
func (g *GroupComposer) Loggable() bool
Loggable returns true if at least one of the constituent Composers is loggable.
func (*GroupComposer) Messages ¶
func (g *GroupComposer) Messages() []Composer
Messages returns a the underlying collection of messages.
func (*GroupComposer) Priority ¶
func (g *GroupComposer) Priority() level.Priority
Priority returns the highest priority of the constituent Composers.
func (*GroupComposer) Raw ¶
func (g *GroupComposer) Raw() interface{}
Raw returns a slice of interfaces containing the raw form of all the constituent composers.
func (*GroupComposer) SetPriority ¶
func (g *GroupComposer) SetPriority(l level.Priority) error
SetPriority sets the priority of all constituent Composers *only* if the existing level is unset, and does not propagate an error, but will *not* unset the level of the compser and will return an error in this case.
func (*GroupComposer) String ¶
func (g *GroupComposer) String() string
String satisfies the fmt.Stringer interface, and returns a string of the string form of all constituent composers joined with a newline.
type ProcessInfo ¶
type ProcessInfo struct { Message string `json:"message" bson:"message"` Pid int32 `json:"pid" bson:"pid"` Parent int32 `json:"parentPid" bson:"parentPid"` Threads int `json:"numThreads" bson:"numThreads"` Command string `json:"command" bson:"command"` CPU StatCPUTimes `json:"cpu" bson:"cpu"` IoStat process.IOCountersStat `json:"io" bson:"io"` NetStat []net.IOCountersStat `json:"net" bson:"net"` Memory process.MemoryInfoStat `json:"mem" bson:"mem"` MemoryPlatform process.MemoryInfoExStat `json:"memExtra" bson:"memExtra"` Errors []string `json:"errors" bson:"errors"` Base `json:"metadata,omitempty" bson:"metadata,omitempty"` // contains filtered or unexported fields }
ProcessInfo holds the data for per-process statistics (e.g. cpu, memory, io). The Process info composers produce messages in this form.
func (*ProcessInfo) Loggable ¶
func (p *ProcessInfo) Loggable() bool
Loggable returns true when the Processinfo structure has been populated.
func (*ProcessInfo) Raw ¶
func (p *ProcessInfo) Raw() interface{}
Raw always returns the ProcessInfo object, however it will call the Collect method of the base operation first.
func (*ProcessInfo) String ¶
func (p *ProcessInfo) String() string
String returns a string representation of the message, lazily rendering the message, and caching it privately.
type Slack ¶
type Slack struct { Target string `bson:"target" json:"target" yaml:"target"` Msg string `bson:"msg" json:"msg" yaml:"msg"` Attachments []*slack.Attachment `bson:"attachments" json:"attachments" yaml:"attachments"` }
Slack is a message to a Slack channel or user
type SlackAttachment ¶
type SlackAttachment struct { Color string `bson:"color,omitempty" json:"color,omitempty" yaml:"color,omitempty"` Fallback string `bson:"fallback" json:"fallback" yaml:"fallback"` AuthorName string `bson:"author_name,omitempty" json:"author_name,omitempty" yaml:"author_name,omitempty"` AuthorIcon string `bson:"author_icon,omitempty" json:"author_icon,omitempty" yaml:"author_icon,omitempty"` Title string `bson:"title,omitempty" json:"title,omitempty" yaml:"title,omitempty"` TitleLink string `bson:"title_link,omitempty" json:"title_link,omitempty" yaml:"title_link,omitempty"` Text string `bson:"text" json:"text" yaml:"text"` Fields []*SlackAttachmentField `bson:"fields,omitempty" json:"fields,omitempty" yaml:"fields,omitempty"` MarkdownIn []string `bson:"mrkdwn_in,omitempty" json:"mrkdwn_in,omitempty" yaml:"mrkdwn_in,omitempty"` }
SlackAttachment is a single attachment to a slack message. This type is the same as bluele/slack.Attachment
type SlackAttachmentField ¶
type SlackAttachmentField struct { Title string `bson:"title" json:"title" yaml:"title"` Value string `bson:"value" json:"value" yaml:"value"` Short bool `bson:"short" json:"short" yaml:"short"` }
SlackAttachmentField is one of the optional fields that can be attached to a slack message. This type is the same as bluele/slack.AttachmentField
type StackFrame ¶
type StackFrame struct { Function string `bson:"function" json:"function" yaml:"function"` File string `bson:"file" json:"file" yaml:"file"` Line int `bson:"line" json:"line" yaml:"line"` }
StackFrame captures a single item in a stack trace, and is used internally and in the StackTrace output.
func (StackFrame) String ¶
func (f StackFrame) String() string
type StackFrames ¶
type StackFrames []StackFrame
StackFrames makes slices of stack traces printable.
func (StackFrames) String ¶
func (f StackFrames) String() string
type StackTrace ¶
type StackTrace struct { Context interface{} `bson:"context,omitempty" json:"context,omitempty" yaml:"context,omitempty"` Frames StackFrames `bson:"frames" json:"frames" yaml:"frames"` }
StackTrace structs are returned by the Raw method of the stackMessage type
func (StackTrace) String ¶
func (s StackTrace) String() string
type StatCPUTimes ¶
type StatCPUTimes struct { User int64 `json:"user" bson:"user"` System int64 `json:"system" bson:"system"` Idle int64 `json:"idle" bson:"idle"` Nice int64 `json:"nice" bson:"nice"` Iowait int64 `json:"iowait" bson:"iowait"` Irq int64 `json:"irq" bson:"irq"` Softirq int64 `json:"softirq" bson:"softirq"` Steal int64 `json:"steal" bson:"steal"` Guest int64 `json:"guest" bson:"guest"` GuestNice int64 `json:"guestNice" bson:"guestNice"` }
StatCPUTimes provides a mirror of gopsutil/cpu.TimesStat with integers rather than floats.
type SystemInfo ¶
type SystemInfo struct { Message string `json:"message" bson:"message"` CPU StatCPUTimes `json:"cpu" bson:"cpu"` CPUPercent float64 `json:"cpu_percent" bson:"cpu_percent"` NumCPU int `json:"num_cpus" bson:"num_cpus"` VMStat mem.VirtualMemoryStat `json:"vmstat" bson:"vmstat"` NetStat net.IOCountersStat `json:"netstat" bson:"netstat"` Partitions []disk.PartitionStat `json:"partitions" bson:"partitions"` Usage []disk.UsageStat `json:"usage" bson:"usage"` IOStat []disk.IOCountersStat `json:"iostat" bson:"iostat"` Errors []string `json:"errors" bson:"errors"` Base `json:"metadata,omitempty" bson:"metadata,omitempty�"` // contains filtered or unexported fields }
SystemInfo is a type that implements message.Composer but also collects system-wide resource utilization statistics about memory, CPU, and network use, along with an optional message.
func (*SystemInfo) Loggable ¶
func (s *SystemInfo) Loggable() bool
Loggable returns true when the Processinfo structure has been populated.
func (*SystemInfo) Raw ¶
func (s *SystemInfo) Raw() interface{}
Raw always returns the SystemInfo object.
func (*SystemInfo) String ¶
func (s *SystemInfo) String() string
String returns a string representation of the message, lazily rendering the message, and caching it privately.