Socket
Socket
Sign inDemoInstall

@jclem/logfmt2

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @jclem/logfmt2

Parses logs and stringifies logs into the logfmt format


Version published
Weekly downloads
9.4K
decreased by-3.88%
Maintainers
1
Install size
20.0 kB
Created
Weekly downloads
 

Readme

Source

logfmt2

logfmt2 (which is based on the original logfmt and the original blog post) is a module for encoding objects into the logfmt format and decoding them again.

Install

npm install @jclem/logfmt2

Build

script/build

Publish

The script/publish script cleans the build directory, builds the project, and then runs npm publish.

script/publish

Usage

const {Logger, encode, decode} = require('@jclem/logfmt2')

console.log(encode({foo: 'bar'})) // foo=bar
console.log(decode('foo=bar')) // {foo: 'bar'}

// Use the static `Logger.log` to stdout
Logger.log({foo: 'bar'}) // logs "foo=bar"

// Create a logger to maintain a logging context
const logger = new Logger({ns: 'my-app'})
logger.log({foo: 'bar'}) // logs "ns=my-app foo=bar"

// Add timers
logger.time('elapsedMs')
// Wait 50ms
logger.log({foo: 'bar'}) // logs "ns=my-app elapsedMs=50 foo=bar"
// Wait 50ms
logger.log({foo: 'bar'}) // logs "ns=my-app elapsedMs=100 foo=bar"

// Add (mutate) the logger context
logger.appendContext({new_context: 'hello'})
logger.log({foo: 'bar'}) // logs "ns=my-app new_context=hello elapsedMs=100 foo=bar"

Keywords

FAQs

Last updated on 20 Oct 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc