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 LogLevel)
- func SetDebugLogging()
- func SetLogLevel(name, level string) error
- func SetLogLevelRegex(e, l string) error
- func SetupLogging()
- type EventInProgress
- type EventLogger
- type LogLevel
- type Loggable
- type LoggableF
- type LoggableMap
- type Metadata
- type StandardLogger
- type ZapEventLogger
- func (el *ZapEventLogger) Event(ctx context.Context, event string, metadata ...Loggable)deprecated
- func (el *ZapEventLogger) EventBegin(ctx context.Context, event string, metadata ...Loggable) *EventInProgressdeprecated
- func (el *ZapEventLogger) Finish(ctx context.Context)deprecated
- func (el *ZapEventLogger) FinishWithErr(ctx context.Context, err error)deprecated
- func (el *ZapEventLogger) LogKV(ctx context.Context, alternatingKeyValues ...interface{})deprecated
- func (el *ZapEventLogger) SerializeContext(ctx context.Context) ([]byte, error)deprecated
- func (el *ZapEventLogger) SetErr(ctx context.Context, err error)deprecated
- func (el *ZapEventLogger) SetTag(ctx context.Context, k string, v interface{})deprecated
- func (el *ZapEventLogger) SetTags(ctx context.Context, tags map[string]interface{})deprecated
- func (el *ZapEventLogger) Start(ctx context.Context, operationName string) context.Contextdeprecated
- func (el *ZapEventLogger) StartFromParentState(ctx context.Context, operationName string, parent []byte) (context.Context, error)deprecated
- func (el *ZapEventLogger) Warning(args ...interface{})deprecated
- func (el *ZapEventLogger) Warningf(format string, args ...interface{})deprecated
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( LevelDebug = log2.LevelDebug LevelInfo = log2.LevelInfo LevelWarn = log2.LevelWarn LevelError = log2.LevelError LevelDPanic = log2.LevelDPanic LevelPanic = log2.LevelPanic LevelFatal = log2.LevelFatal )
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 ¶
func SetAllLoggers(lvl LogLevel)
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 SetLogLevelRegex ¶ added in v1.0.0
SetLogLevelRegex sets all loggers to level `l` that match expression `e`. An error is returned if `e` fails to compile.
func SetupLogging ¶
func SetupLogging()
Types ¶
type EventInProgress ¶
type EventInProgress struct {
// contains filtered or unexported fields
}
DEPRECATED EventInProgress represent and event which is happening Deprecated: Stop using go-log for event logging
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
Close is an alias for done Deprecated: Stop using go-log for event logging
func (*EventInProgress) Done ¶
func (eip *EventInProgress) Done()
Done creates a new Event entry that includes the duration and appended loggables. Deprecated: Stop using go-log for event logging
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 // Deprecated: Stop using go-log for event logging Event(ctx context.Context, event string, m ...Loggable) // DEPRECATED // Deprecated: Stop using go-log for event logging 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) // ... // } // Deprecated: Stop using go-log for event logging 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) // ... // } // Deprecated: Stop using go-log for event logging 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` // Deprecated: Stop using go-log for event logging 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` // Deprecated: Stop using go-log for event logging 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`. // Deprecated: Stop using go-log for event logging 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) // Deprecated: Stop using go-log for event logging LogKV(ctx context.Context, alternatingKeyValues ...interface{}) // SetTag tags key `k` and value `v` on the span associated with `ctx` // Deprecated: Stop using go-log for event logging 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, // }) // Deprecated: Stop using go-log for event logging 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 // Deprecated: Stop using go-log for event logging 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 LogLevel ¶ added in v1.0.0
LogLevel represents a log severity level. Use the package variables as an enum.
func LevelFromString ¶ added in v1.0.0
LevelFromString parses a string-based level and returns the corresponding LogLevel.
Supported strings are: DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL, and their lower-case forms.
The returned LogLevel must be discarded if error is not nil.
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 { log2.StandardLogger // Deprecated use Warn Warning(args ...interface{}) // Deprecated use Warnf Warningf(format string, args ...interface{}) }
StandardLogger provides API compatibility with standard printf loggers eg. go-logging
type ZapEventLogger ¶ added in v1.0.0
type ZapEventLogger struct { zap.SugaredLogger // contains filtered or unexported fields }
ZapEventLogger implements the EventLogger and wraps a go-logging Logger
func (*ZapEventLogger) EventBegin
deprecated
added in
v1.0.0
func (el *ZapEventLogger) EventBegin(ctx context.Context, event string, metadata ...Loggable) *EventInProgress
Deprecated: Stop using go-log for event logging
func (*ZapEventLogger) Finish
deprecated
added in
v1.0.0
func (el *ZapEventLogger) Finish(ctx context.Context)
Deprecated: Stop using go-log for event logging
func (*ZapEventLogger) FinishWithErr
deprecated
added in
v1.0.0
func (el *ZapEventLogger) FinishWithErr(ctx context.Context, err error)
Deprecated: Stop using go-log for event logging
func (*ZapEventLogger) LogKV
deprecated
added in
v1.0.0
func (el *ZapEventLogger) LogKV(ctx context.Context, alternatingKeyValues ...interface{})
Deprecated: Stop using go-log for event logging
func (*ZapEventLogger) SerializeContext
deprecated
added in
v1.0.0
func (el *ZapEventLogger) SerializeContext(ctx context.Context) ([]byte, error)
Deprecated: Stop using go-log for event logging
func (*ZapEventLogger) SetErr
deprecated
added in
v1.0.0
func (el *ZapEventLogger) SetErr(ctx context.Context, err error)
Deprecated: Stop using go-log for event logging
func (*ZapEventLogger) SetTag
deprecated
added in
v1.0.0
func (el *ZapEventLogger) SetTag(ctx context.Context, k string, v interface{})
Deprecated: Stop using go-log for event logging
func (*ZapEventLogger) SetTags
deprecated
added in
v1.0.0
func (el *ZapEventLogger) SetTags(ctx context.Context, tags map[string]interface{})
Deprecated: Stop using go-log for event logging
func (*ZapEventLogger) StartFromParentState
deprecated
added in
v1.0.0
func (*ZapEventLogger) Warning
deprecated
added in
v1.0.0
func (el *ZapEventLogger) Warning(args ...interface{})
Deprecated: use Warn
func (*ZapEventLogger) Warningf
deprecated
added in
v1.0.0
func (el *ZapEventLogger) Warningf(format string, args ...interface{})
Deprecated: use Warnf