next-splunk-logger
Logs stuff directly to splunk.
Prerequites
Requires a SPLUNK_URL environment variable to send stuff to. If you don't have one, talk to someone.
Usage
npm install --save ft-next-splunk-logger
The logger works pretty much the same as the debug module.
var log = require('ft-next-splunk-logger')('my-app-name');
log('Some stuff');
It will stick the app name and a timestamp at the beginnig of each log so the above will become
my-app-name 2015-05-30T12:54:54.479Z Some stuff
Like debug and console.log in node it uses util.format under the hood if the first arg is a string
log('here is a %s and %j', 'string', {foo:'bar'})
becomes:
here is a string and {"foo":"bar"}
Apparently splunk can parse json so the above should work well. But to make it easier if you pass just an object it will be formatted in the easiet way for splunk:
log({foo:'here is a string'})
becomes
foo="here is a string"
You can also pass it errors (but please don't, send them to sentry or somewhere useful):
log(new Error('bar'));
becomes:
Error: bar
Formatting Options
When passing a string as the first argument, the following placeholders can be used:
%s
Will replace the argument usingString(arg)
- objects will appear as 'Object object' or similar%d
Will replace the argument usingNumber(arg)
- anything that is not a number will appear as "NaN"%j
Will replace the argument usingJSON.stringify(arg)
- will throw an error if it doesn't get an a object%o
Will replace the argument using the splunk-friendly name=value style - will probably thrown an error if not given an object