Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
github.com/ipfs/go-log
The logging library used by go-ipfs
It currently uses a modified version of go-logging to implement the standard printf-style log output.
go get github.com/ipfs/go-log
Once the package 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.
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)
}
...
}
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
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.
MIT
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.