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

fable-log

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fable-log - npm Package Compare versions

Comparing version 1.0.10 to 2.0.0

.vscode/launch.json

8

CHANGELOG.md

@@ -14,2 +14,8 @@ # Change Log

* Added automagic Mongo init (previously you had to explicitly init Mongodbs)
* Changed UUID to use fable-uuid
* Changed UUID to use fable-uuid
#### 2019-05-10: Steven Velozo
* Changed everything to es6 classes
* Added a lighter web built version via gulp
* Added timing methods for easy profiling
* Providers are abstracted to separate classes (e.g. so bunyan isn't built into the web version)

39

package.json
{
"name": "fable-log",
"version": "1.0.10",
"version": "2.0.0",
"description": "A simple logging wrapper.",

@@ -8,4 +8,5 @@ "main": "source/Fable-Log.js",

"start": "node source/Fable-Log.js",
"coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
"test": "./node_modules/mocha/bin/_mocha -u tdd -R spec"
"coverage": "./node_modules/nyc/bin/nyc.js --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
"test": "./node_modules/mocha/bin/_mocha -u tdd -R spec",
"harness": "node debug/Harness.js"
},

@@ -24,22 +25,28 @@ "repository": {

},
"browser": {
"./source/Fable-Log-DefaultProviders.js": "./source/Fable-Log-DefaultProviders-Browser.js"
},
"homepage": "https://github.com/stevenvelozo/fable-log",
"devDependencies": {
"async": "2.6.1",
"chai": "4.1.2",
"codeclimate-test-reporter": "0.5.0",
"coveralls": "3.0.2",
"istanbul": "0.4.5",
"mocha": "5.2.0"
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"async": "^2.6.2",
"browserify": "^16.2.3",
"chai": "4.2.0",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-sourcemaps": "^2.6.5",
"gulp-terser": "^1.1.7",
"gulp-util": "^3.0.8",
"mocha": "6.1.4",
"nyc": "^14.1.0",
"vinyl-buffer": "^1.0.1",
"vinyl-source-stream": "^2.0.0"
},
"dependencies": {
"bunyan": "1.8.12",
"bunyan-elasticsearch": "^1.0.0",
"bunyan": "^1.8.12",
"bunyan-logstash-tcp": "^1.0.0",
"bunyan-mongo": "0.1.0",
"bunyan-prettystream": "^0.1.3",
"fable-uuid": "~1.0.1",
"gelf-stream": "^1.1.0",
"mongodb": "2.2.10",
"underscore": "1.9.1"
"fable-uuid": "^2.0.0"
}
}

@@ -18,6 +18,9 @@ Fable Logging

```
$ npm install fable-log
```
Then everything should just work, without configuration, as a bunyan console logger:
```
var fableLog = require('fable-log').new();

@@ -31,5 +34,7 @@ fableLog.initialize();

fableLog.fatal('Testing object sending to Fatal...',{Value:"Unlikely",Status:true});
```
Which should output the following garbage-looking content to the command-line:
```
{"name":"Fable","hostname":"Stevens-Mac-Pro.local","pid":58264,"level":10,"Source":"0x532004ec61800000","ver":"0.0.0","datum":{"Value":"Unlikely","Status":true},"msg":"Testing object sending to Trace...","time":"2015-04-03T16:18:36.551Z","v":0}

@@ -41,2 +46,3 @@ {"name":"Fable","hostname":"Stevens-Mac-Pro.local","pid":58264,"level":20,"Source":"0x532004ec61800000","ver":"0.0.0","datum":{"Value":"Unlikely","Status":true},"msg":"Testing object sending to Debug...","time":"2015-04-03T16:18:36.551Z","v":0}

{"name":"Fable","hostname":"Stevens-Mac-Pro.local","pid":58264,"level":60,"Source":"0x532004ec61800000","ver":"0.0.0","datum":{"Value":"Unlikely","Status":true},"msg":"Testing object sending to Fatal...","time":"2015-04-03T16:18:36.551Z","v":0}
```

@@ -48,6 +54,9 @@ But Those Log Entries are Unreadable!

```
$ npm install -g bunyan
```
And then pipe your console output through everybodies favorite lumberjack:
```
$ node MyBestApplicationEver.js | bunyan

@@ -84,2 +93,3 @@ [2015-04-03T16:20:43.435Z] TRACE: Fable/58284 on Stevens-Mac-Pro.local: Testing object sending to Trace... (Source=0x532005684ac00000, ver=0.0.0)

}
```

@@ -90,2 +100,3 @@ If that isn't exciting enough, on my computer these entries are in __all sorts of rainbow colors__!

```
var fableLogOptions = (

@@ -110,5 +121,37 @@ {

fableLog.info('This is really important info.');
```
Which will write the info line to both streams, and the trace line just to the console.
Stream Definitions
------------
A stream definition object has the following options (none are required, defaults are shown):
```
{
loggertype: 'console',
streamtype: 'console',
level: 'trace'
}
```
Stream types can also have their own parameters -- for instance Bunyan has a path for the log file.
```
{
loggertype: 'bunyan',
streamtype: 'process.stdout',
level: 'info'
},
{
loggertype: 'bunyan',
streamtype: 'file',
level: 'trace',
path: './MyFirstLogFile.log'
}
```
Scalable Functionality

@@ -115,0 +158,0 @@ ------------

{
"Product": "Fable",
"ProductVersion": "0.0.1",
"ProductVersion": "2.0.0",
"UUID":
{
"DataCenter": 0,
"Worker": 0
"DataCenter": 1,
"Worker": 1
},

@@ -13,5 +13,5 @@ "LogStreams":

"level": "trace",
"path": "./Logs/Fable.log"
"path": "./Run.log"
}
]
}

@@ -16,239 +16,204 @@ /**

*/
var FableLog = function()
class FableLog
{
function createNew(pFromParameters)
constructor(pFableSettings, pFable)
{
var _Parameters = require('./Fable-Log-Parameters.js').new(pFromParameters);
let tmpSettings = (typeof(pFableSettings) === 'object') ? pFableSettings : {}
this._Settings = tmpSettings;
var _Log = false;
var _UUID = false;
this._Providers = require('./Fable-Log-DefaultProviders.js');
var initialize = function(pConfigurationFileName)
{
var tmpConfigurationFileName = (typeof(pConfigurationFileName) === 'string') ? pConfigurationFileName : false;
this._StreamDefinitions = (tmpSettings.hasOwnProperty('LogStreams')) ? tmpSettings.LogStreams : require('./Fable-Log-DefaultStreams.json');
// Load the configuration file for log parameters, if one exists
if (tmpConfigurationFileName)
{
_Parameters.loadConfiguration(tmpConfigurationFileName);
}
this.logStreams = [];
_Parameters.initializeConfiguration();
// This object gets decorated for one-time instantiated providers that
// have multiple outputs, such as bunyan.
this.logProviders = {};
// Now create the Bunyan log object
_Log = require('bunyan').createLogger(
{
name: _Parameters.parameters.Product,
streams: _Parameters.parseLogStreams(_Parameters.parameters.LogStreams)
});
// A hash list of the GUIDs for each log stream, so they can't be added to the set more than one time
this.activeLogStreams = {};
// Only create a UUID if one wasn't previously set.
if (!_UUID)
{
_UUID = require('fable-uuid').new(_Parameters.parameters).getUUID();
}
this.logStreamsTrace = [];
this.logStreamsDebug = [];
this.logStreamsInfo = [];
this.logStreamsWarn = [];
this.logStreamsError = [];
this.logStreamsFatal = [];
// Automagically initialize the Mongo streams if they haven't been
_Parameters.initializeMongoStreams();
};
this.uuid = (typeof(tmpSettings.Product) === 'string') ? tmpSettings.Product : 'Default';
}
/**
* Write a message to the TRACE stream.
*
* @method logTrace
* @param {String} pMessage A short text description of the event
* @param {Object} pDatum Any objects that are important to this event
* @return {Boolean} Returns whether the log event worked.
*/
var logTrace = function(pMessage, pDatum)
addLogger(pLogger, pLevel)
{
// Bail out if we've already created one.
if (this.activeLogStreams.hasOwnProperty(pLogger.loggerUUID))
{
if (!_Log)
{
return false;
}
return false;
}
var tmpDatum = (typeof(pDatum) === 'undefined') ? {} : pDatum;
var tmpMessage = (typeof(pMessage) !== 'string') ? 'No message' : pMessage;
// Add it to the streams and to the mutex
this.logStreams.push(pLogger);
this.activeLogStreams[pLogger.loggerUUID] = true;
_Log.trace({Source:_UUID, ver:_Parameters.parameters.ProductVersion, datum:tmpDatum}, tmpMessage);
return true;
};
/**
* Write a message to the DEBUG stream.
*
* @method logDebug
* @param {String} pMessage A short text description of the event
* @param {Object} pDatum Any objects that are important to this event
* @return {Boolean} Returns whether the log event worked.
*/
var logDebug = function(pMessage, pDatum)
// Make sure a kosher level was passed in
switch (pLevel)
{
if (!_Log)
{
return false;
}
case 'trace':
this.logStreamsTrace.push(pLogger);
case 'debug':
this.logStreamsDebug.push(pLogger);
case 'info':
this.logStreamsInfo.push(pLogger);
case 'warn':
this.logStreamsWarn.push(pLogger);
case 'error':
this.logStreamsError.push(pLogger);
case 'fatal':
this.logStreamsFatal.push(pLogger);
break;
}
var tmpDatum = (typeof(pDatum) === 'undefined') ? {} : pDatum;
var tmpMessage = (typeof(pMessage) !== 'string') ? 'No message' : pMessage;
return true;
}
_Log.debug({Source:_UUID, ver:_Parameters.parameters.ProductVersion, datum:tmpDatum}, tmpMessage);
return true;
};
trace(pMessage, pDatum)
{
for (let i = 0; i < this.logStreamsTrace.length; i++)
{
this.logStreamsTrace[i].trace(pMessage, pDatum);
}
}
/**
* Write a message to the INFO stream.
*
* @method logInfo
* @param {String} pMessage A short text description of the event
* @param {Object} pDatum Any objects that are important to this event
* @return {Boolean} Returns whether the log event worked.
*/
var logInfo = function(pMessage, pDatum)
debug(pMessage, pDatum)
{
for (let i = 0; i < this.logStreamsDebug.length; i++)
{
if (!_Log)
{
return false;
}
this.logStreamsDebug[i].debug(pMessage, pDatum);
}
}
var tmpDatum = (typeof(pDatum) === 'undefined') ? {} : pDatum;
var tmpMessage = (typeof(pMessage) !== 'string') ? 'No message' : pMessage;
info(pMessage, pDatum)
{
for (let i = 0; i < this.logStreamsInfo.length; i++)
{
this.logStreamsInfo[i].info(pMessage, pDatum);
}
}
_Log.info({Source:_UUID, ver:_Parameters.parameters.ProductVersion, datum:tmpDatum}, tmpMessage);
return true;
};
warn(pMessage, pDatum)
{
for (let i = 0; i < this.logStreamsWarn.length; i++)
{
this.logStreamsWarn[i].warn(pMessage, pDatum);
}
}
/**
* Write a message to the WARNING stream.
*
* @method logWarn
* @param {String} pMessage A short text description of the event
* @param {Object} pDatum Any objects that are important to this event
* @return {Boolean} Returns whether the log event worked.
*/
var logWarn = function(pMessage, pDatum)
error(pMessage, pDatum)
{
for (let i = 0; i < this.logStreamsError.length; i++)
{
if (!_Log)
{
return false;
}
this.logStreamsError[i].error(pMessage, pDatum);
}
}
var tmpDatum = (typeof(pDatum) === 'undefined') ? {} : pDatum;
var tmpMessage = (typeof(pMessage) !== 'string') ? 'No message' : pMessage;
fatal(pMessage, pDatum)
{
for (let i = 0; i < this.logStreamsFatal.length; i++)
{
this.logStreamsFatal[i].fatal(pMessage, pDatum);
}
}
_Log.warn({Source:_UUID, ver:_Parameters.parameters.ProductVersion, datum:tmpDatum}, tmpMessage);
return true;
};
initialize()
{
// "initialize" each logger as defined in the logging parameters
for (let i = 0; i < this._StreamDefinitions.length; i++)
{
let tmpStreamDefinition = Object.assign({loggertype:'console',streamtype:'console',level:'info'},this._StreamDefinitions[i]);
/**
* Write a message to the ERROR stream.
*
* @method logError
* @param {String} pMessage A short text description of the event
* @param {Object} pDatum Any objects that are important to this event
* @return {Boolean} Returns whether the log event worked.
*/
var logError = function(pMessage, pDatum)
{
if (!_Log)
if (!this._Providers.hasOwnProperty(tmpStreamDefinition.loggertype))
{
return false;
console.log(`Error initializing log stream: bad loggertype in stream definition ${JSON.stringify(tmpStreamDefinition)}`);
}
else
{
this.addLogger(new this._Providers[tmpStreamDefinition.loggertype](tmpStreamDefinition, this), tmpStreamDefinition.level);
}
}
var tmpDatum = (typeof(pDatum) === 'undefined') ? {} : pDatum;
var tmpMessage = (typeof(pMessage) !== 'string') ? 'No message' : pMessage;
// Now initialize each one.
for (let i = 0; i < this.logStreams.length; i++)
{
this.logStreams[i].initialize();
}
}
_Log.error({Source:_UUID, ver:_Parameters.parameters.ProductVersion, datum:tmpDatum}, tmpMessage);
return true;
};
logTime(pMessage, pDatum)
{
let tmpMessage = (typeof(pMessage) !== 'undefined') ? pMessage : 'Time';
let tmpTime = new Date();
this.info(`${tmpMessage} ${tmpTime} (epoch ${+tmpTime})`, pDatum);
}
/**
* Write a message to the FATAL stream.
*
* @method logFatal
* @param {String} pMessage A short text description of the event
* @param {Object} pDatum Any objects that are important to this event
* @return {Boolean} Returns whether the log event worked.
*/
var logFatal = function(pMessage, pDatum)
{
if (!_Log)
{
return false;
}
// Get a timestamp
getTimeStamp()
{
return +new Date();
}
var tmpDatum = (typeof(pDatum) === 'undefined') ? {} : pDatum;
var tmpMessage = (typeof(pMessage) !== 'string') ? 'No message' : pMessage;
getTimeDelta(pTimeStamp)
{
let tmpEndTime = +new Date();
return tmpEndTime-pTimeStamp;
}
_Log.fatal({Source:_UUID, ver:_Parameters.parameters.ProductVersion, datum:tmpDatum}, tmpMessage);
return true;
};
// Log the delta between a timestamp, and now with a message
logTimeDelta(pTimeDelta, pMessage, pDatum)
{
let tmpMessage = (typeof(pMessage) !== 'undefined') ? pMessage : 'Time Measurement';
let tmpDatum = (typeof(pDatum) === 'object') ? pDatum : {};
let tmpEndTime = +new Date();
/**
* Container Object for our Factory Pattern
*/
var tmpNewFableLogObject = (
{
initialize: initialize,
initializeMongoStreams: _Parameters.initializeMongoStreams,
this.info(`${tmpMessage} logged at (epoch ${+tmpEndTime}) took (${pTimeDelta}ms)`, pDatum);
}
trace: logTrace,
debug: logDebug,
info: logInfo,
warn: logWarn,
error: logError,
fatal: logFatal,
logTimeDeltaHuman(pTimeDelta, pMessage, pDatum)
{
let tmpMessage = (typeof(pMessage) !== 'undefined') ? pMessage : 'Time Measurement';
new: createNew
});
let tmpEndTime = +new Date();
/**
* Raw Bunyan Logger
*
* This is exposed for complex logging calls. Only recommended for debug and
* lower level logging.
*
* @property logger
* @type Object
*/
Object.defineProperty(tmpNewFableLogObject, 'logger',
{
get: function() { return _Log; },
enumerable: false
});
let tmpMs = parseInt(pTimeDelta%1000);
let tmpSeconds = parseInt((pTimeDelta/1000)%60);
let tmpMinutes = parseInt((pTimeDelta/(1000*60))%60);
let tmpHours = parseInt(pTimeDelta/(1000*60*60));
/**
* Log File Parameters
*
* @property parameters
* @type Object
*/
Object.defineProperty(tmpNewFableLogObject, 'parameters',
{
get: function() { return _Parameters; },
set: function(pParameters) { _Parameters = pParameters; },
enumerable: true
});
tmpMs = (tmpMs < 10) ? "00"+tmpMs : (tmpMs < 100) ? "0"+tmpMs : tmpMs;
tmpSeconds = (tmpSeconds < 10) ? "0"+tmpSeconds : tmpSeconds;
tmpMinutes = (tmpMinutes < 10) ? "0"+tmpMinutes : tmpMinutes;
tmpHours = (tmpHours < 10) ? "0"+tmpHours : tmpHours;
/**
* Universally Unique Identifier
*
* @property uuid
* @type string
*/
Object.defineProperty(tmpNewFableLogObject, 'uuid',
{
get: function() { return _UUID; },
set: function(pUUID) { _UUID = pUUID; },
enumerable: true
});
this.info(`${tmpMessage} logged at (epoch ${+tmpEndTime}) took (${pTimeDelta}ms) or (${tmpHours}:${tmpMinutes}:${tmpSeconds}.${tmpMs})`, pDatum);
}
return tmpNewFableLogObject;
logTimeDeltaRelative(pStartTime, pMessage, pDatum)
{
this.logTimeDelta(this.getTimeDelta(pStartTime), pMessage, pDatum);
}
return createNew();
};
logTimeDeltaRelativeHuman(pStartTime, pMessage, pDatum)
{
this.logTimeDeltaHuman(this.getTimeDelta(pStartTime), pMessage, pDatum);
}
}
module.exports = new FableLog();
// This is for backwards compatibility
function autoConstruct(pSettings)
{
return new FableLog(pSettings);
}
module.exports = {new:autoConstruct, FableLog:FableLog};

@@ -13,2 +13,4 @@ /**

var libFableLog = require('../source/Fable-Log.js').FableLog;
suite

@@ -36,3 +38,3 @@ (

{
var tmpFableLog = require('../source/Fable-Log.js').new();
var tmpFableLog = new libFableLog();
Expect(tmpFableLog)

@@ -49,10 +51,20 @@ .to.be.an('object', 'Fable-Log should initialize as an object directly from the require statement.');

tmpFableLog.initialize();
Expect(tmpFableLog).to.have.a.property('parameters')
Expect(tmpFableLog).to.have.a.property('_Settings')
.that.is.a('object');
Expect(tmpFableLog).to.have.a.property('logger')
.that.is.a('object');
Expect(tmpFableLog).to.have.a.property('uuid')
.that.is.a('string');
}
);
test
(
'instantiate a base logger class',
function()
{
var tmpFableLogBaseLogger = require('../source/Fable-Log-BaseLogger.js');
var tmpBaseLogger = new tmpFableLogBaseLogger({});
Expect(tmpBaseLogger)
.to.be.an('object');
Expect(tmpBaseLogger.write()).to.equal(true);
}
);
}

@@ -73,2 +85,4 @@ );

tmpFableLog.info('Test');
tmpFableLog.logTime();
tmpFableLog.logTime('Time logged...', {With:'someobject'});
}

@@ -78,3 +92,25 @@ );

(
'writing to all log streams',
'writing custom time events to a log stream',
function(fNext)
{
var tmpFableLog = require('../source/Fable-Log.js').new();
tmpFableLog.initialize();
let tmpTimeStamp = tmpFableLog.getTimeStamp();
setTimeout(
()=>
{
let tmpTimeDelta = tmpFableLog.getTimeDelta(tmpTimeStamp);
tmpFableLog.logTimeDelta(tmpTimeDelta);
tmpFableLog.logTimeDeltaHuman(tmpTimeDelta);
tmpFableLog.logTimeDeltaRelative(tmpTimeStamp, 'Relative Deltas', {Some:'value'});
tmpFableLog.logTimeDeltaRelativeHuman(tmpTimeStamp, 'Relative Deltas', {Some:'value'});
fNext();
}, 505);
}
);
test
(
'shorter time spans',
function()

@@ -84,2 +120,32 @@ {

tmpFableLog.initialize();
let tmpTimeStamp = tmpFableLog.getTimeStamp();
tmpFableLog.logTimeDeltaHuman(1, 'Relative Deltas', {Some:'value'});
tmpFableLog.logTimeDeltaHuman(10, 'Relative Deltas', {Some:'value'});
tmpFableLog.logTimeDeltaHuman(100, 'Relative Deltas', {Some:'value'});
tmpFableLog.logTimeDeltaHuman(1000, 'Relative Deltas', {Some:'value'});
tmpFableLog.logTimeDeltaHuman(10000, 'Relative Deltas', {Some:'value'});
tmpFableLog.logTimeDeltaHuman(100000, 'Relative Deltas', {Some:'value'});
tmpFableLog.logTimeDeltaHuman(700000, 'Relative Deltas', {Some:'value'});
tmpFableLog.logTimeDeltaHuman(144000000, 'Relative Deltas', {Some:'value'});
}
);
test
(
'empty log streams array',
function()
{
var tmpFableLog = require('../source/Fable-Log.js').new({LogStreams:[]});
tmpFableLog.initialize();
tmpFableLog.info('Test');
}
);
test
(
'writing to all log streams',
function()
{
var tmpFableLog = require('../source/Fable-Log.js').new({LogStreams:[{Context:'Testing Purposes', ShowTimeStamps:true, FormattedTimeStamps:false}]});
tmpFableLog.initialize();
tmpFableLog.trace('Test of Trace');

@@ -95,2 +161,17 @@ tmpFableLog.debug('Test of Debug');

(
'writing to all log streams with a context',
function()
{
var tmpFableLog = require('../source/Fable-Log.js').new({LogStreams:[{Context:'Testing Purposes', ShowTimeStamps:true, FormattedTimeStamps:true}]});
tmpFableLog.initialize();
tmpFableLog.trace('Test of Trace');
tmpFableLog.debug('Test of Debug');
tmpFableLog.info('Test of Info');
tmpFableLog.warn('Test of Warning');
tmpFableLog.error('Test of Error');
tmpFableLog.fatal('Test of Fatal');
}
);
test
(
'writing objects to all log streams',

@@ -126,2 +207,17 @@ function()

(
'trying to add a bad logger',
function()
{
var tmpFableLog = require('../source/Fable-Log.js').new({LogStreams:[{loggertype:'badmojo',StreamType:'process.stderr'}]});
tmpFableLog.initialize();
tmpFableLog.trace('Test of Trace');
tmpFableLog.debug('Test of Debug');
tmpFableLog.info('Test of Info');
tmpFableLog.warn('Test of Warning');
tmpFableLog.error('Test of Error');
tmpFableLog.fatal('Test of Fatal');
}
);
test
(
'logging empty values to all log streams',

@@ -145,5 +241,5 @@ function()

{
var tmpFableLog = require('../source/Fable-Log.js').new();
var tmpFableLog = require('../source/Fable-Log.js').new({LogStreams:[{level:'trace'}]});
tmpFableLog.initialize();
tmpFableLog.logger.trace('Test of manual Trace');
tmpFableLog.logStreamsTrace[0].trace('Test of manual Trace');
}

@@ -171,15 +267,2 @@ );

(
'passing parameters in',
function()
{
var tmpFableLog = require('../source/Fable-Log.js').new({Product:'ForcedProduct'});
tmpFableLog.initialize();
tmpFableLog.info('Test 3');
Expect(tmpFableLog.parameters.parameters.Product)
.to.equal('ForcedProduct')
}
);
test
(
'setting a UUID',

@@ -206,10 +289,59 @@ function()

(
'passing in a parameters object',
'passing in the rotating file parameter',
function(fDone)
{
var tmpFableLog = require('../source/Fable-Log.js').new({Product:'rotatingoooo', LogStreams:[{streamtype:'process.stdout'},{type:'rotating-file', period:'1ms', path:'/tmp/SomeRotatingLog.log'}]});
tmpFableLog.initialize();
// We have to do this as a series, so we can ensure the connection is done before we start logging.
var libAsync = require('async');
libAsync.series([
function(fNext)
{
tmpFableLog.info('Test with custom param object: '+tmpFableLog.uuid);
tmpFableLog.info('Test with custom param object: '+tmpFableLog.uuid);
fDone();
fNext();
}
]);
}
);
}
);
suite
(
'Bunyan',
function()
{
test
(
'create a bunyan logger',
function()
{
var tmpFableLog = require('../source/Fable-Log.js').new({Product:'Paramset', ProductVersion:'9.8.7'});
// This should overwrite the parameters we set above entirely.
tmpFableLog.parameters = require('../source/Fable-Log-Parameters.js').new();
var tmpFableLog = new libFableLog(
{
LogStreams:
[
{
loggertype:'bunyan',
streamtype:'stdout',
level:'debug'
},
{
loggertype:'bunyan',
level:'debug',
streamtype:'file',
path:'./Test-Bunyan.log'
}
]
});
Expect(tmpFableLog)
.to.be.an('object', 'Bunyan loggers should initialize properly.');
tmpFableLog.initialize();
tmpFableLog.info('Test with custom param object: '+tmpFableLog.uuid);
tmpFableLog.trace('Bunyan to Trace...',{Value:"Unlikely",Status:false});
tmpFableLog.debug('Bunyan to Debug...',{Value:"Unlikely",Status:true});
tmpFableLog.info('Bunyan to Info...',{Value:"Unlikely",Status:true});
tmpFableLog.warn('Bunyan to Warning...',{Value:"Unlikely",Status:true});
tmpFableLog.error('Bunyan to Error...',{Value:"Unlikely",Status:true});
tmpFableLog.fatal('Bunyan to Fatal...',{Value:"Unlikely",Status:true});
}

@@ -222,3 +354,18 @@ );

{
var tmpFableLog = require('../source/Fable-Log.js').new({Product:'PrettyStream', LogStreams:[{streamtype:'prettystream'}]});
var tmpFableLog = require('../source/Fable-Log.js').new(
{
LogStreams:
[
{
loggertype:'bunyan',
streamtype:'stdout',
level:'trace'
},
{
loggertype:'bunyan',
level:'trace',
streamtype:'prettystream'
}
]
});
tmpFableLog.initialize();

@@ -235,8 +382,23 @@ tmpFableLog.trace('Trying out pretty streams to Trace...',{Value:"Unlikely",Status:true});

(
'passing in a bad mongoDB parameter',
function(fDone)
'pretty streams default content',
function()
{
var tmpFableLog = require('../source/Fable-Log.js').new({Product:'Mongoooo', LogStreams:[{streamtype:'mongodb'}], MongoDBURL: 'mongodb://baddburl'});
var tmpFableLog = require('../source/Fable-Log.js').new(
{
LogStreams:
[
{
loggertype:'bunyan',
level:'trace',
streamtype:'prettystream'
}
]
});
tmpFableLog.initialize();
tmpFableLog.initializeMongoStreams(fDone);
tmpFableLog.trace();
tmpFableLog.debug();
tmpFableLog.info();
tmpFableLog.warn();
tmpFableLog.error();
tmpFableLog.fatal();
}

@@ -246,22 +408,38 @@ );

(
'passing in the rotating file parameter',
function(fDone)
'other stream output options',
function()
{
var tmpFableLog = require('../source/Fable-Log.js').new({Product:'Mongoooo', LogStreams:[{streamtype:'process.stdout'},{type:'rotating-file', period:'1ms', path:'/tmp/SomeRotatingLog.log'}]});
var tmpFableLog = require('../source/Fable-Log.js').new(
{
LogStreams:
[
{
loggertype:'bunyan',
streamtype:'stderr',
level:'trace'
},
{
loggertype:'bunyan',
streamtype:'process.stderr',
level:'trace'
},
{
loggertype:'bunyan',
streamtype:'process.stdout',
level:'trace'
},
{
loggertype:'bunyan',
level:'trace',
streamtype:'prettystream'
}
]
});
tmpFableLog.initialize();
// We have to do this as a series, so we can ensure the connection is done before we start logging.
var libAsync = require('async');
libAsync.series([
function(fNext)
{
tmpFableLog.initializeMongoStreams(fNext);
},
function(fNext)
{
tmpFableLog.info('Test with custom param object: '+tmpFableLog.uuid);
tmpFableLog.info('Test with custom param object: '+tmpFableLog.uuid);
fDone();
fNext();
}
]);
tmpFableLog.trace('Trying out pretty streams to Trace...',{Value:"Unlikely",Status:true});
tmpFableLog.debug('Trying out pretty streams to Debug...',{Value:"Unlikely",Status:true});
tmpFableLog.info('Trying out pretty streams to Info...',{Value:"Unlikely",Status:true});
tmpFableLog.warn('Trying out pretty streams to Warning...',{Value:"Unlikely",Status:true});
tmpFableLog.error('Trying out pretty streams to Error...',{Value:"Unlikely",Status:true});
tmpFableLog.fatal('Trying out pretty streams to Fatal...',{Value:"Unlikely",Status:true});
}

@@ -271,39 +449,33 @@ );

(
'passing in the mongoDB parameter',
function(fDone)
'create a logstash stream',
function()
{
var tmpFableLog = require('../source/Fable-Log.js').new({Product:'Mongoooo', LogStreams:[{streamtype:'process.stdout'},{streamtype:'mongodb'}]});
var tmpFableLog = require('../source/Fable-Log.js').new(
{
LogStreams:
[
{
loggertype:'bunyan',
level:'trace'
},
{
loggertype:'bunyan',
streamtype:'logstash',
level:'trace'
}
]
});
tmpFableLog.initialize();
// We have to do this as a series, so we can ensure the connection is done before we start logging.
var libAsync = require('async');
libAsync.series([
function(fNext)
{
tmpFableLog.initializeMongoStreams(fNext);
},
function(fNext)
{
tmpFableLog.info('Test with custom param object: '+tmpFableLog.uuid);
tmpFableLog.info('Test with custom param object: '+tmpFableLog.uuid);
fDone();
fNext();
}
]);
tmpFableLog.trace('Trying out pretty streams to Trace...',{Value:"Unlikely",Status:true});
tmpFableLog.debug('Trying out pretty streams to Debug...',{Value:"Unlikely",Status:true});
tmpFableLog.info('Trying out pretty streams to Info...',{Value:"Unlikely",Status:true});
tmpFableLog.warn('Trying out pretty streams to Warning...',{Value:"Unlikely",Status:true});
tmpFableLog.error('Trying out pretty streams to Error...',{Value:"Unlikely",Status:true});
tmpFableLog.fatal('Trying out pretty streams to Fatal...',{Value:"Unlikely",Status:true});
}
);
test
(
'implicit mongodb initialization',
function(fDone)
{
var tmpFableLog = require('../source/Fable-Log.js').new({Product:'Mongoooo', LogStreams:[{streamtype:'process.stdout'},{streamtype:'mongodb'}]});
tmpFableLog.initialize();
// We have to do this as a series, so we can ensure the connection is done before we start logging.
tmpFableLog.info('Test without explicit mongo initialization '+tmpFableLog.uuid);
tmpFableLog.initializeMongoStreams(fDone);
}
);
}
);
}
);

Sorry, the diff of this file is not supported yet

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