Documentation ¶
Index ¶
- func DevNullAppender() (send.Sender, error)
- func FormatLog(log *Log) string
- func LevelFilter(threshold Level, sender send.Sender) send.Sender
- func NewAppenderSender(name string, a Appender) send.Sender
- func NewStringAppender(buffer *bytes.Buffer) send.Sender
- func StdErrAppender() send.Sender
- func StdOutAppender() send.Sender
- func WrapAppender(a Appender) send.Sender
- type Appender
- type Level
- type Log
- type Logger
- type SenderAppender
- type StackError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DevNullAppender ¶
DevNullAppender returns a configured stream logger Sender instance that writes messages to dev null.
func LevelFilter ¶
LevelFilter provides compatibility with a legacy slogger implementation that filgered messages lower than the specified priority. This implementation simply sets the threshold level on that sender and returns it.
func NewAppenderSender ¶
NewAppenderSender implements the send.Sender interface, which allows it to be used as a grip backend, but the it's mode of action is to use a slogger.Appender. This allows using the grip package, either via the slogger interface or the normal grip Jouernaler interface, while continuing to use existing slogger code.
func NewStringAppender ¶
NewStringAppender wraps a bytes.Buffer and provides an send.Sender/Appender interface that writes log messages to that buffer.
func StdErrAppender ¶
StdErrAppender returns a configured stream logger Sender instance that writes messages to standard error.
func StdOutAppender ¶
StdOutAppender returns a configured stream logger Sender instance that writes messages to standard output.
func WrapAppender ¶
WrapAppender takes an Appender instance and returns a send.Sender instance that wraps it. The name defaults to the name of the process (argc).
Types ¶
type Appender ¶
Appender is the slogger equivalent of a send.Sender, and this provides the same public interface for Appenders, in terms of Grip's senders.
type Level ¶
type Level uint8
Level represents slogger's level types. In the original implementation there are four levels and an "OFF" value.
slogger has its own system of priorities/log levels. These constants represent those levels, and the Level type can be converted to grip level.Priority values.
type Log ¶
type Log struct { Prefix string `bson:"prefix,omitempty" json:"prefix,omitempty" yaml:"prefix,omitempty"` Level Level `bson:"level" json:"level" yaml:"level"` Filename string `bson:"filename" json:"filename" yaml:"filename"` Line int `bson:"line" json:"line" yaml:"line"` Timestamp time.Time `bson:"timestamp" json:"timestamp" yaml:"timestamp"` Output string `bson:"message,omitempty" json:"message,omitempty" yaml:"message,omitempty"` // contains filtered or unexported fields }
Log is a representation of a logging event, which matches the structure and interface of the original slogger Log type. Additionally implements grip's "message.Composer" interface for use with other logging mechanisms.
Note that the String() method, which Sender's use to format the output of the log lines includes timestamp and component (name/prefix) information.
func NewLog ¶
NewLog takes a message.Composer object and returns a slogger.Log instance (which also implements message.Composer). This method records its callsite, so you ought to call this method directly.
func NewPrefixedLog ¶
NewPrefixedLog allows you to construct a slogger.Log message from a message composer, while specifying a prefix.
type Logger ¶
Logger is a type that represents a single log instance. This is analogous to the original slogger's Logger type; however, the Appender field stores a slice of sned.Senders rather than slogger.Appenders; however, the Appender type is defined in the new slogger, and the NewAppenderSender and WrapAppender functions afford the conversion.
func (*Logger) Errorf ¶
Errorf logs and returns its message as an error.
Log and return a formatted error string. Example:i
if whatIsExpected != whatIsReturned { return slogger.Errorf(slogger.WARN, "Unexpected return value. Expected: %v Received: %v", whatIsExpected, whatIsReturned) }
func (*Logger) Logf ¶
Logf logs a message and a level to a logger instance. This returns a pointer to a Log and a slice of errors that were gathered from every Appender (nil errors included).
In this implementation, Logf will never return an error. This part of the type definition was retained for backwards compatibility
func (*Logger) Stackf ¶
func (l *Logger) Stackf(level Level, stackErr error, messageFmt string, args ...interface{}) (*Log, []error)
Stackf is designed to work in tandem with `NewStackError`. This function is similar to `Logf`, but takes a `stackErr` parameter. `stackErr` is expected to be of type StackError, but does not have to be.
In this implementation, Logf will never return an error. This part of the type definition was retained for backwards compatibility.
An additional difference is that the new implementation, will not log if the error is nil, and the previous implementation would.
type SenderAppender ¶
SenderAppender is a shim that implements the Appender interface around any arbitrary sender instance.
func (SenderAppender) Append ¶
func (s SenderAppender) Append(log *Log) error
Append sends a log message. This method *always* returns nil.
type StackError ¶
type StackError struct { message.Composer Stacktrace []string // contains filtered or unexported fields }
StackError is a grip re implementation of a type from legacy slogger. It combines a stacktrace of the call site of the logged message and a message composer. StackError also implements the error interface. The composer's "loggability" is derived from the embedded composer.
func NewStackError ¶
func NewStackError(messageFmt string, args ...interface{}) *StackError
NewStackError produces a StackError object, collecting the stacktrace and building a Formatted message composer (e.g. fmt.Sprintf).
func (*StackError) Error ¶
func (s *StackError) Error() string
Error returns the resolved error message for the StackError instance and satisfies the error interface.
func (*StackError) Raw ¶
func (s *StackError) Raw() interface{}
Raw produces a structure that contains the mesage, stacktrace, and raw metadata from the embedded composer for use by some logging backends.
func (*StackError) String ¶
func (s *StackError) String() string
String lazily resolves a message for the instance and caches that message internally.