🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

tclogformat

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tclogformat

stringify objects into searchable strings

2.0.1
latest
Source
npm
Version published
Weekly downloads
55
-57.69%
Maintainers
1
Weekly downloads
 
Created
Source

tclogformat

Stringify objects into searchable strings.

Motivation

JSON is a great format for exchanging data, but it isn't so great for logging. Say I want to log the follow user request object:

{
    date: '2015-11-19',
    client: {
        agent: 'firefox',
        ip: '10.1.32.1'
    },
    server: {
        ip: '192.168.2.222'
    }
}

If I use the traditional JSON.stringify(), I get something like this:

{"date":"2015-11-19","client":{"agent":"firefox","ip":"10.1.32.1"},"server":{"ip":"192.168.2.222"}}

That isn't very readable and hard to grep. This library solves those problems by nicely formatting objects as key=value pairs:

date=2015-11-19 client.agent=firefox client.ip=10.1.32.1 server.ip=192.168.2.222

Installation

npm install --save tclogformat

API

tclogformat(any)

Parameters:

  • any anything you wish to stringify... booleans, strings, numbers, objects, arrays, etc.

Returns:

  • formatted string

Example

var tclogformat = require('tclogformat');
var fs = require('fs');

console.log(tclogformat(fs.statSync('/dev/null')));

// -> 'dev=6 mode=8630 nlink=1 uid=0 gid=0 rdev=259 blksize=4096 ino=1029 size=0 blocks=0 atime=2017-07-12T00:21:34-04:00 mtime=2017-07-12T00:21:34-04:00 ctime=2017-07-12T00:21:34-04:00 birthtime=2017-07-12T00:21:34-04:00'

Testing

There is an automated test suite:

npm test

License

See LICENSE.md

Keywords

log

FAQs

Package last updated on 29 Nov 2018

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