Documentation ¶
Overview ¶
Package log is the logging library used by IPFS (https://github.com/ipfs/go-ipfs). It uses a modified version of https://godoc.org/github.com/whyrusleeping/go-logging .
Index ¶
- Variables
- func ContextWithLoggable(ctx context.Context, l Loggable) context.Context
- func FormatRFC3339(t time.Time) string
- func GetSubsystems() []string
- func SetAllLoggers(lvl logging.Level)
- func SetDebugLogging()
- func SetLogLevel(name, level string) error
- func SetupLogging()
- type EventInProgress
- type EventLogger
- type Loggable
- type LoggableF
- type LoggableMap
- type Metadata
- type StandardLogger
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoSuchLogger = errors.New("Error: No such logger")
ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
var LogFormats = map[string]string{
"nocolor": "%{time:2006-01-02 15:04:05.000000} %{level} %{module} %{shortfile}: %{message}",
"color": ansiGray + "%{time:15:04:05.000} %{color}%{level:5.5s} " + ansiBlue +
"%{module:10.10s}: %{color:reset}%{message} " + ansiGray + "%{shortfile}%{color:reset}",
}
LogFormats defines formats for logging (i.e. "color")
Functions ¶
func ContextWithLoggable ¶
ContextWithLoggable returns a derived context which contains the provided Loggable. Any Events logged with the derived context will include the provided Loggable.
func FormatRFC3339 ¶
FormatRFC3339 returns the given time in UTC with RFC3999Nano format.
func GetSubsystems ¶
func GetSubsystems() []string
GetSubsystems returns a slice containing the names of the current loggers
func SetAllLoggers ¶
SetAllLoggers changes the logging.Level of all loggers to lvl
func SetDebugLogging ¶
func SetDebugLogging()
SetDebugLogging calls SetAllLoggers with logging.DEBUG
func SetLogLevel ¶
SetLogLevel changes the log level of a specific subsystem name=="*" changes all subsystems
func SetupLogging ¶
func SetupLogging()
SetupLogging will initialize the logger backend and set the flags. TODO calling this in `init` pushes all configuration to env variables - move it out of `init`? then we need to change all the code (js-ipfs, go-ipfs) to call this explicitly - have it look for a config file? need to define what that is
Types ¶
type EventInProgress ¶
type EventInProgress struct {
// contains filtered or unexported fields
}
DEPRECATED EventInProgress represent and event which is happening
func (*EventInProgress) Append ¶
func (eip *EventInProgress) Append(l Loggable)
DEPRECATED use `LogKV` or `SetTag` Append adds loggables to be included in the call to Done
func (*EventInProgress) Close ¶
func (eip *EventInProgress) Close() error
DEPRECATED use `Finish` Close is an alias for done
func (*EventInProgress) Done ¶
func (eip *EventInProgress) Done()
DEPRECATED use `Finish` Done creates a new Event entry that includes the duration and appended loggables.
func (*EventInProgress) DoneWithErr ¶
func (eip *EventInProgress) DoneWithErr(err error)
DEPRECATED use `FinishWithErr` DoneWithErr creates a new Event entry that includes the duration and appended loggables. DoneWithErr accepts an error, if err is non-nil, it is set on the EventInProgress. Otherwise the logic is the same as the `Done()` method
func (*EventInProgress) SetError ¶
func (eip *EventInProgress) SetError(err error)
DEPRECATED use `SetError(ctx, error)` SetError includes the provided error
type EventLogger ¶
type EventLogger interface { StandardLogger // Event merges structured data from the provided inputs into a single // machine-readable log event. // // If the context contains metadata, a copy of this is used as the base // metadata accumulator. // // If one or more loggable objects are provided, these are deep-merged into base blob. // // Next, the event name is added to the blob under the key "event". If // the key "event" already exists, it will be over-written. // // Finally the timestamp and package name are added to the accumulator and // the metadata is logged. // DEPRECATED Event(ctx context.Context, event string, m ...Loggable) // DEPRECATED EventBegin(ctx context.Context, event string, m ...Loggable) *EventInProgress // Start starts an opentracing span with `name`, using // any Span found within `ctx` as a ChildOfRef. If no such parent could be // found, Start creates a root (parentless) Span. // // The return value is a context.Context object built around the // returned Span. // // Example usage: // // SomeFunction(ctx context.Context, ...) { // ctx := log.Start(ctx, "SomeFunction") // defer log.Finish(ctx) // ... // } Start(ctx context.Context, name string) context.Context // StartFromParentState starts an opentracing span with `name`, using // any Span found within `ctx` as a ChildOfRef. If no such parent could be // found, StartSpanFromParentState creates a root (parentless) Span. // // StartFromParentState will attempt to deserialize a SpanContext from `parent`, // using any Span found within to continue the trace // // The return value is a context.Context object built around the // returned Span. // // An error is returned when `parent` cannot be deserialized to a SpanContext // // Example usage: // // SomeFunction(ctx context.Context, bParent []byte) { // ctx := log.StartFromParentState(ctx, "SomeFunction", bParent) // defer log.Finish(ctx) // ... // } StartFromParentState(ctx context.Context, name string, parent []byte) (context.Context, error) // Finish completes the span associated with `ctx`. // // Finish() must be the last call made to any span instance, and to do // otherwise leads to undefined behavior. // Finish will do its best to notify (log) when used in correctly // .e.g called twice, or called on a spanless `ctx` Finish(ctx context.Context) // FinishWithErr completes the span associated with `ctx` and also calls // SetErr if `err` is non-nil // // FinishWithErr() must be the last call made to any span instance, and to do // otherwise leads to undefined behavior. // FinishWithErr will do its best to notify (log) when used in correctly // .e.g called twice, or called on a spanless `ctx` FinishWithErr(ctx context.Context, err error) // SetErr tags the span associated with `ctx` to reflect an error occured, and // logs the value `err` under key `error`. SetErr(ctx context.Context, err error) // LogKV records key:value logging data about an event stored in `ctx` // Eexample: // log.LogKV( // "error", "resolve failure", // "type", "cache timeout", // "waited.millis", 1500) LogKV(ctx context.Context, alternatingKeyValues ...interface{}) // SetTag tags key `k` and value `v` on the span associated with `ctx` SetTag(ctx context.Context, key string, value interface{}) // SetTags tags keys from the `tags` maps on the span associated with `ctx` // Example: // log.SetTags(ctx, map[string]{ // "type": bizStruct, // "request": req, // }) SetTags(ctx context.Context, tags map[string]interface{}) // SerializeContext takes the SpanContext instance stored in `ctx` and Seralizes // it to bytes. An error is returned if the `ctx` cannot be serialized to // a bytes array SerializeContext(ctx context.Context) ([]byte, error) }
EventLogger extends the StandardLogger interface to allow for log items containing structured metadata
Example ¶
{ log := EventLogger(nil) e := log.EventBegin(context.Background(), "dial") e.Done() } { log := EventLogger(nil) e := log.EventBegin(context.Background(), "dial") _ = e.Close() // implements io.Closer for convenience }
Output:
type Loggable ¶
type Loggable interface {
Loggable() map[string]interface{}
}
Loggable describes objects that can be marshalled into Metadata for logging
type LoggableF ¶
type LoggableF func() map[string]interface{}
LoggableF converts a func into a Loggable
type LoggableMap ¶
type LoggableMap map[string]interface{}
LoggableMap is just a generic map keyed by string. It implements the Loggable interface.
func (LoggableMap) Loggable ¶
func (l LoggableMap) Loggable() map[string]interface{}
Loggable implements the Loggable interface for LoggableMap
type Metadata ¶
type Metadata map[string]interface{}
Metadata is a convenience type for generic maps
func DeepMerge ¶
DeepMerge merges the second Metadata parameter into the first. Nested Metadata are merged recursively. Primitives are over-written.
func MetadataFromContext ¶
MetadataFromContext extracts Matadata from a given context's value.
func Metadatify ¶
Metadatify converts maps into Metadata.
func (Metadata) JsonString ¶
JsonString returns the marshaled JSON string for the metadata.
type StandardLogger ¶
type StandardLogger interface { Debug(args ...interface{}) Debugf(format string, args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Info(args ...interface{}) Infof(format string, args ...interface{}) Panic(args ...interface{}) Panicf(format string, args ...interface{}) Warning(args ...interface{}) Warningf(format string, args ...interface{}) }
StandardLogger provides API compatibility with standard printf loggers eg. go-logging