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

feather

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feather - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

.idea/featherLog.iml

19

config/featherProperties.js

@@ -1,19 +0,4 @@

/**
* properties that can be set are as follows
*
* fileLocation (required) - the path to where the log files should be written too
* appName (optional) - this is to help distinguish between different app logs - this will be more useful when feather is able to write to system-wide logs via syslog or rsyslog
* timestampFormat (optional / recommend using) - this is the date format appearing in the log file. The one used here is apache style and is widely used.
* dateFormat (required) - this is how the file name will appear as feather uses this to create the file name. Again, this conforms with current convention so I recommend not changing it
* host (optional) - this is the host and again it will be useful when feather writes to system log facilities such as syslog
* rootLevel (optional) - if set then only logs up to that level will be logged, others will be ignored.
*/
module.exports = {
"fileLocation": "logs/feather/",
"appName": "Feather",
"timestampFormat" : "ddd, dd MMM yyyy HH:mm:ss",
"dateFormat" : "yyyyMMdd",
"host" : '172.0.0.1',
"rootLevel" : "Warn"
"timestampFormat" : "dddd, MMMM Do YYYY, h:mm:ss a",
"level" : "Info"
}

@@ -1,119 +0,38 @@

require('datejs');
var GLOBAL_CONFIG = '../../../config/featherProperties'
var sys = require('sys');
var fs = require('fs');
try { // Try loading configuration from the user application level
var config = require(GLOBAL_CONFIG);
} catch(e) { // if one does not exist then use the one set here
config = require('../config')
}
var levels = require('../config/loggerLevels');
var appName = config.appName;
var filename = config.fileLocation + new Date().toString(config.dateFormat);
var Logger = exports;
var util = require('util');
var moment = require('moment');
var config = require('loggerProperties')
var timestamp = function() {
return new Date().toString(config.timestampFormat); //TODO get the timestamp format from config too
}
Logger.LEVELS = [
'Emergency',
'Alert',
'Critical',
'Error',
'Warn',
'Notice',
'Info',
'Debug'
];
/**
* calculate the root level and return a value
* so if Info is stated in configuration then only log up to that level and no debug messages will be logged
*
* @return numerical value representing the log level to be used
*
* @param callback function
*/
var getHighestLevelToLogToo = function(callback) {
var rootLevel = config.rootLevel;
if (rootLevel) {
Object.keys(levels.alertLevels).forEach(function(key) {
if (levels.alertLevels[key].toLowerCase() === rootLevel.toLowerCase()) {
callback(null, key);
}
});
} else { // log everything
Object.keys(levels.alertLevels).forEach(function(key) {
if(levels.alertLevels[key].toLowerCase() === "debug") {
callback(null, key);
}
})
}
}
Logger.LEVEL = Logger.LEVELS.indexOf(config.level);
/**
* Check if a given directory exists and if not, create it so feather can start logging
*
*/
var createRequiredDirectory = function() {
var dirPath = '';
var dirs = config.fileLocation.split('/'); // get individual dirs from the give location in the config file.
Logger.LEVELS.forEach(function(level, index) {
var method = level.toLowerCase();
var target = (index > Logger.LEVELS.indexOf('Error'))
? 'stdout'
: 'stderr';
for(var i = 0; i < dirs.length; i++) {
if(dirs[i] != '') {
dirPath += (dirs[i] + '/');
try {
if(!fs.lstatSync(dirPath)) { // check to see if directory already exists
fs.mkdirSync(dirPath, '0755'); // if not then create it
}
} catch(error) {
throw 'Failed to create directory ' + dirPath;
}
Logger[method] = function() {
if (index > Logger.LEVEL) return;
}
}
}
var message = Logger.format.apply(Logger, arguments);
process[target].write('[' + level + '] ' + message);
};
});
/**
* Go through the alert level JSON object and dynamically create a function which will log data for that alert code
*/
var init = function() {
createRequiredDirectory();
getHighestLevelToLogToo(function(error, alertLevelNumber) {
Object.keys(levels.alertLevels).forEach(function(key) {
Logger[levels.alertLevels[key].toLowerCase()] = function(message) {
fs.open(filename, 'a', undefined, function(err, fd) {
if (err) {
throw err;
}
if (alertLevelNumber && key <= alertLevelNumber) {
fs.write(fd, config.host + ' [' + timestamp() +
'] ' + levels.alertLevels[key].toUpperCase() +
': ' + appName + ': ' + message + '\n', undefined, undefined,
function(err, written) {
if (err) {
throw err;
}
// sys.puts(written + ' bytes written');
fs.close(fd, function(err) {
if (err) {
throw err;
}
});
});
}
});
}
});
});
}
/**
* Initialize logger
*/
init();
/**
* Tackle the following in order
*/
//TODO - Create directories as required [DONE]
//TODO - to read configuration from app level conf file.
//TODO - Branch and rename to featherLog
//TODO - allow log file locking so that one process can write to it at any one time. ~ careful that it does not slow things down though
//TODO - start() stop() to yield time between the two
//TODO - TCP / UDP connection
Logger.format = function(/* template, arg1, arg2, ... */) {
var message = util.format.apply(util, arguments);
var timestamp = moment().format(config.timestampFormat);
message = timestamp + ': ' + message + '\n';
return message;
};
{
"name":"feather",
"version":"0.0.2",
"version":"0.0.3",
"keywords": ["logger", "lightweight", "Unix style logging", "info debug warn"],

@@ -11,5 +11,6 @@ "engines": { "node": "*"},

},
"repository": { "type": "git", "url": "git@github.com:holidayextras/feather.git"},
"repository": { "type": "git", "url": "git@github.com:holidayextras/featherLog.git"},
"dependencies":{
"datejs":"0.0.2"
"utest" : "0.0.6",
"utest" : "0.0.2"
},

@@ -16,0 +17,0 @@ "licenses": [

var logger = require('../lib/logger');
var assert = require('assert');
var fail = [];
var pass = [];
var warn = [];
var test = require('utest');
exports.runTest = function(cb) {
var count = 0;
var test = function(name, method, warning) {
count++;
try {
method();
if (warning) {
warn.push({test:count, method:name, message:warning});
} else {
pass.push({test:count, method:name});
}
} catch(e) {
fail.push({test:count, method:name, exception:e});
test('Running tests', {
'before' : function() {
this.loggerLevels = ['info', 'warn', 'error', 'emergency', 'alert', 'critical', 'debug', 'notice'];
},
'Test all available logger levels': function() {
for (var i = 0; i < this.loggerLevels.length; i++) {
test('all logger level \"' + this.loggerLevels[i] + '\", logs OK! Exception is thrown in event of a failure!', function() {
try {
logger[this.loggerLevels[i]]('Testing logger level ' + loggerLevels[i]);
//also check log file for current date to ensure that all is logged properly!
} catch (e) {
throw(e);
}
})
}
}
var loggerLevels = ['info', 'warn', 'error', 'emergency', 'alert', 'critical', 'debug', 'notice']
for (var i = 0; i < loggerLevels.length; i++) {
test('all logger level \"' + loggerLevels[i] + '\", logs OK! Exception is thrown in event of a failure!', function() {
try {
logger[loggerLevels[i]]('Testing logger level ' + loggerLevels[i]);
//also check log file for current date to ensure that all is logged properly!
} catch (e) {
throw(e);
}
})
}
test('Exception is thrown when logging with level that is not defined!', function() {
},
'Exception is thrown when logging with level that is not defined!' : function() {
assert.throws(function() {
logger.foo('foobar');
});
});
cb(fail, warn, pass);
}
this.runTest(function(fail, warn, pass) {
if (fail.size > 0 ) {
fail.forEach(function(message) {
console.log(message);
})
}if (warn.size > 0 ) {
fail.forEach(function(message) {
console.log(message);
})
}if (pass.size > 0 ) {
fail.forEach(function(message) {
console.log(message);
})
}
})
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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