Skip to content
/ logus Public

Logus is a structured context aware logger for Go (golang)

License

Notifications You must be signed in to change notification settings

strongo/logus

Repository files navigation

Package strongo/logus provides structured context aware logging for Go (golang) that supports grouping of log entries using trace and span IDs.

Usage

package foo

import "context"
import "github.com/strongo/logus"

func init() {
  logus.AddLogEntryHandler(logus.StandardGoLogger())
  Bar(context.Background())
}

// Bar demonstrates how to use logus logger 
func Bar(c context.Context) {

	logus.Debugf(c, "This is a debug message without trace ID, unless it was set outside")
  
	const traceID = "123"
	ct := logus.WithTraceID(c, traceID)
	logus.Infof(ct, "This is an info message with a traceID=%s", traceID)

	const spanID = "456"
	ct = logus.WithSpanID(ct, spanID)
	logus.Warningf(ct, "A warning with same trace ID and additional spanID=%s", spanID)
  
	logus.Logf(c, logus.SeverityError, "This is an error log message without trace ID")
}

Logus log entry handlers

About

Logus is a structured context aware logger for Go (golang)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages