Categorygithub.com/dms3-fs/go-log
modulepackage
1.5.3
Repository: https://github.com/dms3-fs/go-log.git
Documentation: pkg.go.dev

# README

go-log

standard-readme compliant GoDoc Build Status

The logging library used by go-ipfs

It currently uses a modified version of go-logging to implement the standard printf-style log output.

Install

go get github.com/ipfs/go-log

Usage

Once the pacakge is imported under the name logging, an instance of EventLogger can be created like so:

var log = logging.Logger("subsystem name")

It can then be used to emit log messages, either plain printf-style messages at six standard levels or structured messages using Start, StartFromParentState, Finish and FinishWithErr methods.

Example

func (s *Session) GetBlock(ctx context.Context, c *cid.Cid) (blk blocks.Block, err error) {

    // Starts Span called "Session.GetBlock", associates with `ctx`
    ctx = log.Start(ctx, "Session.GetBlock")

    // defer so `blk` and `err` can be evaluated after call
    defer func() {
        // tag span associated with `ctx`
        log.SetTags(ctx, map[string]interface{}{
            "cid": c,
            "block", blk,
        })
        // if err is non-nil tag the span with an error
        log.FinishWithErr(ctx, err)
    }()

    if shouldStartSomething() {
        // log message on span associated with `ctx`
        log.LogKV(ctx, "startSomething", true)
    }
  ...
}

Tracing

go-log wraps the opentracing-go methods - StartSpan, Finish, LogKV, and SetTag.

go-log implements its own tracer - loggabletracer - based on the basictracer-go implementation. If there is an active WriterGroup the loggabletracer will record span data to the WriterGroup. An example of this can be seen in the log tail command of go-ipfs.

Third party tracers may be used by calling opentracing.SetGlobalTracer() with your desired tracing implementation. An example of this can be seen using the go-jaeger-plugin and the go-ipfs tracer plugin

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

Want to hack on IPFS?

License

MIT

# Packages

No description provided by the author
No description provided by the author

# Functions

ContextWithLoggable returns a derived context which contains the provided Loggable.
DeepMerge merges the second Metadata parameter into the first.
Deferred returns a LoggableF where the execution of the provided function is deferred.
FormatRFC3339 returns the given time in UTC with RFC3999Nano format.
GetSubsystems returns a slice containing the names of the current loggers.
Logger retrieves an event logger by name.
MetadataFromContext extracts Matadata from a given context's value.
Metadatify converts maps into Metadata.
Pair returns a Loggable where key is paired to Loggable.
SetAllLoggers changes the logging.Level of all loggers to lvl.
SetDebugLogging calls SetAllLoggers with logging.DEBUG.
SetLogLevel changes the log level of a specific subsystem name=="*" changes all subsystems.
SetupLogging will initialize the logger backend and set the flags.

# Variables

ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger.
LogFormats defines formats for logging (i.e.

# Structs

DEPRECATED EventInProgress represent and event which is happening.

# Interfaces

EventLogger extends the StandardLogger interface to allow for log items containing structured metadata.
Loggable describes objects that can be marshalled into Metadata for logging.
StandardLogger provides API compatibility with standard printf loggers eg.

# Type aliases

LoggableF converts a func into a Loggable.
LoggableMap is just a generic map keyed by string.
Metadata is a convenience type for generic maps.