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

logfmt

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logfmt - npm Package Compare versions

Comparing version 1.0.0 to 1.1.1

examples/simple_cmd.js

27

examples/timed_log.js
var logfmt = require('../logfmt');
logfmt.time('thing', function(logger){
logger.log({foo: 'bar'})
var this_thing = function(){
var logger = logfmt.time('thing')
logger.log({foo: 'bar'})
var this_thing = function(){
logfmt.log({at: "logfmt log"})
logger.log({at: "thing"})
var inner_logger = logger.time()
var inner_thing = function(){
logfmt.log({at: "logfmt log"})
logger.log({at: "thing"})
logfmt.log({at: "logfmt log"})
logfmt.time(function(inner_logger){
var inner_thing = function(){
inner_logger.log({at: 'inner thing'});
}
setTimeout(inner_thing, 100);
})
inner_logger.log({at: 'inner thing'});
}
setTimeout(this_thing, 300);
})
setTimeout(inner_thing, 100);
}
setTimeout(this_thing, 300);

@@ -9,5 +9,7 @@ var _ = require('lodash');

if(this.timerNow){
var now = (new Date()).getTime()
logData[this.timerKey] = (now - this.timerNow).toString() + 'ms' ;
if(this.timers){
for(var key in this.timers){
var now = (new Date()).getTime()
logData[key] = (now - this.timers[key]).toString() + 'ms' ;
}
}

@@ -25,4 +27,4 @@

timer.defaultData = this.defaultData;
timer.timerKey = label;
timer.timerNow = startTime;
timer.timers = _.extend({}, this.timers)
timer.timers[label] = startTime;
return timer;

@@ -37,4 +39,3 @@ }

namespaced.defaultData = namespace
namespaced.timerKey = this.timerKey;
namespaced.timerNow = this.timerNow;
namespaced.timers = this.timers;
return namespaced;

@@ -41,0 +42,0 @@ }

@@ -5,6 +5,2 @@ var split = require('split')

function trimNewline(line) {
return line.replace(/\r?\n/, '');
}
//returns a stream that splits and parses logfmt into objects

@@ -15,3 +11,3 @@ exports.streamParser = function(options){

var streamParser = new PassThrough();
var splitter = split(/\b\r?\n\b/, trimNewline, null)
var splitter = split(/\b\r?\n/)
var self = this;

@@ -28,3 +24,3 @@

streamParser.on('pipe', function(source) {
source.unpipe(this);
if(source.unpipe) source.unpipe(this);
this.transformStream = source.pipe(splitter).pipe(logfmtStream);

@@ -31,0 +27,0 @@ });

{
"name": "logfmt",
"version": "1.0.0",
"version": "1.1.1",
"description": "key=value logger and parser",

@@ -5,0 +5,0 @@ "main": "logfmt.js",

@@ -19,3 +19,3 @@ # node-logfmt

npm install logfmt@1.0.0-pre3
npm install logfmt

@@ -113,2 +113,4 @@ # use

Put this in your pipe and smoke it.
### `logfmt.streamParser()`

@@ -119,2 +121,4 @@

Stream in from STDIN
```javascript

@@ -124,2 +128,4 @@ process.stdin.pipe(logfmt.streamParser())

Or pipe from an HTTP request
```javascript

@@ -148,39 +154,34 @@ req.pipe(logfmt.streamParser())

#### Example
Example command line of parsing logfmt and echoing JSON:
Example command line of parsing logfmt and echoing objects to STDOUT:
```javascript
var jsonOut = through(function(line){
this.queue(JSON.stringify(line))
}, function(){
this.queue(null)
})
var logfmt = require('logfmt');
var through = require('through');
process.stdin
.pipe(logfmt.streamParser())
.pipe(jsonOut)
.pipe(process.stdout)
.pipe(through(function(object){
console.log(object);
}))
```
Example HTTP request parsing logfmt and echoing JSON:
Example HTTP request parsing logfmt and echoing objects to STDOUT:
```
server.post('/logs', function(req, res, next){
```javascript
var http = require('http');
var logfmt = require('logfmt');
var through = require('through');
var jsonOut = through(function(line){
this.queue(JSON.stringify(line))
}, function(){
this.queue(null)
})
http.createServer(function (req, res) {
req.pipe(logfmt.streamParser())
.pipe(jsonOut)
.pipe(process.stdout);
.pipe(through(function(object){
console.log(object);
}))
return next();
})
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('OK');
}).listen(3000);
```

@@ -465,1 +466,13 @@

```
# Development
Pull Requests welcome.
## Tests
> npm test
# License
MIT

@@ -69,2 +69,26 @@ var logfmt = require('../logfmt'),

test('can nest multiple timers', function(){
var logger = logfmt.time('foo');
var logger2 = logger.time('foo2');
var logger3 = logger2.time('foo3');
var mock_sink = new OutStream;
logger2.log({}, mock_sink);
var recovered = logfmt.parse(mock_sink.logline);
console.log(recovered);
assert(/^\d+ms/.test(recovered.foo));
assert(/^\d+ms/.test(recovered.foo2));
assert(recovered.foo3 === undefined);
var mock_sink2 = new OutStream;
logger3.log({}, mock_sink2);
var recovered = logfmt.parse(mock_sink2.logline);
console.log(recovered);
assert(/^\d+ms/.test(recovered.foo));
assert(/^\d+ms/.test(recovered.foo2));
assert(/^\d+ms/.test(recovered.foo3));
})
// tests you can pass the logger into a closure

@@ -71,0 +95,0 @@ // and call `log` multiple times.

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