{"library":"logfmt","title":"logfmt: Key-Value Logger and Parser","description":"logfmt is a Node.js library for working with the key-value logging convention popularized by Heroku. It provides functionalities for both serializing JavaScript objects into logfmt strings (e.g., `foo=bar a=14 baz=\"hello kitty\"`) and parsing logfmt strings back into objects. The library also includes streaming capabilities for processing logfmt data from sources like `stdin` or HTTP requests, making it suitable for creating logplex drains or general structured log consumption/production. Currently at version 1.4.0, the package has not seen active development or releases since 2018, indicating an abandoned status. Its key differentiator is its direct support for the logfmt format, unlike general-purpose JSON loggers, making it specific to ecosystems leveraging this convention.","language":"javascript","status":"abandoned","last_verified":"Tue Apr 21","install":{"commands":["npm install logfmt"],"cli":null},"imports":["const logfmt = require('logfmt');","const logfmt = require('logfmt');\nlogfmt.stringify({ key: 'value' });","const logfmt = require('logfmt');\nlogfmt.parse('key=value');","const logfmt = require('logfmt');\nprocess.stdin.pipe(logfmt.streamParser());"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const logfmt = require('logfmt');\nconst through = require('through'); // often used for stream manipulation\n\n// --- Non-streaming usage ---\nconst data = { status: 200, method: 'GET', path: '/api/items', duration_ms: 50 };\nconst logString = logfmt.stringify(data);\nconsole.log('Stringified:', logString);\n// Expected: Stringified: status=200 method=GET path=/api/items duration_ms=50\n\nconst parsedObject = logfmt.parse('status=200 method=GET path=/api/items duration_ms=50');\nconsole.log('Parsed:', parsedObject);\n// Expected: Parsed: { status: '200', method: 'GET', path: '/api/items', duration_ms: '50' }\n\n// --- Streaming usage (parsing logfmt from a simulated input) ---\nconst { Readable } = require('stream');\nconst simulatedInput = new Readable({\n  read() {\n    this.push('metric=cpu_usage value=0.5 host=web-01\\n');\n    this.push('metric=memory_free value=1024 host=db-01\\n');\n    this.push(null); // No more data\n  }\n});\n\nconsole.log('\\n--- Streaming Parse Output ---');\nsimulatedInput\n  .pipe(logfmt.streamParser())\n  .pipe(through(function(obj) {\n    console.log('Streamed Object:', obj);\n  }));\n// Expected: Streamed Object: { metric: 'cpu_usage', value: '0.5', host: 'web-01' }\n// Expected: Streamed Object: { metric: 'memory_free', value: '1024', host: 'db-01' }","lang":"javascript","description":"Demonstrates basic `stringify` and `parse` operations, then shows how to use `streamParser` to process logfmt data from a simulated stream.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}