Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/etnz/logfmt

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/etnz/logfmt

  • v0.0.0-20160225225243-5594cfea30ac
  • Source
  • Go
  • Socket score

Version published
Created
Source

#logfmt Travis GoDoc

  • Package "logfmt" implements a logger for objects in logfmt format: details
  • Package "logfmt/logreader" implements a parser for logfmt streams: details
  • Package "logfmt/ql" implements an interpreter of a query language for logfmt records. details
  • Package "logfmt/cmd" is a collection of command line utilities for working with logfmt, it complements brandur's own collection. details

#logfmt

To use the package:

go get github.com/etnz/logfmt

logfmt is defined in Brandur's blog as a logging format optimal for easy development, consistency, and good legibility for humans and computers.

at=info method=GET path=/ host=mutelight.org status=200

The example above can be generated like:

logfmt.
  S("at", "info").
  S("method",r.Method).
  S("path", r.URL.Path).
  D("status", code ).
  Log()

Where 'S', 'Q', 'D' are method mapping the usual 'fmt' verbs.

Key/Value are stored in a map, so it's ok to call S("at", "info") several time, the last one is always right.

When writing the line in the output stream, keys are not printed in random order. Logs would be hard to read, and not reproducible. Instead key/value pairs are sorted in significance order: the shortest keys first, then alphabetically

at=info path=/ host=mutelight.org method=GET status=200

It enforce the tendency to keep generic keys short, and specific one longer, the first information you read is the most important.

Usually it is faster than the default "log" package

    r := Rec()
    r.D("timestamp", int(n))
    r.D("at", i)
    r.Q("username", "eric")
    r.K("debug")
    r.Log()

At 1389 ns/op : 720 logs per milliseconds

     log.Printf("at=%d", i)
     log.Printf("debug")
     log.Printf("username=%q\n", "eric")

At 2248 ns/op, that is 445 logs per milliseconds

Because using logfmt, you tend to group together information in less records, but richer, I compared a single logfmt record with 4 attributes with a 3 default logs.

'Record' object is idiomatic:

log:= logfmt.Rec()
defer log.Log()
//set an initial value
r.S("level", "debug")
...
if err != nil{
  r.S("level", "error") // escalate the record
  r.V("err", err)
}

See Examples or directly the godoc for more details.

Still on the workbench

  • rewriter logs (sort keys, filter out some matches), highlight lowlight some lines or keys
  • trim logs (before first match and after last match)

FAQs

Package last updated on 25 Feb 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc