Skip to content

Commit

Permalink
Refactored constructor, Added api-doc comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
thakkar-rushikesh committed Apr 6, 2012
1 parent c4f9bc2 commit f11f802
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/log.js
Expand Up @@ -4,15 +4,26 @@
* MIT Licensed
*/

/**
* Functions to support Log rotation
/**
* Returns the next date of the given date
*
* @author thakkar.rushikesh
* @param Date
* @type Date
*/
function getNextDate(dt) {
var nxt = new Date();
nxt.setDate(dt.getDate()+1);
return nxt;
}

/**
* Returns the number of milliseconds remaining for rotation.
*
* @author thakkar.rushikesh
* @param {Number} hourOfTheDay - in 24hrs format
* @type Number
*/
function calculateTimeToRotate(rotationTime) {
var milliSeconds;
if (rotationTime) {
Expand Down Expand Up @@ -44,7 +55,6 @@ var EventEmitter = require('events').EventEmitter;
* @param {Object} stream
* @api public
*/

var Log = exports = module.exports = function Log(level, stream, userPrefs){

if ('string' == typeof level) level = exports[level.toUpperCase()];
Expand All @@ -55,11 +65,11 @@ var Log = exports = module.exports = function Log(level, stream, userPrefs){
this.rotate = false;
if(userPrefs) {
this.rotate = userPrefs.rotate || false;
this.rotationTime = userPrefs.rotationTime || 0;
this.timeToRotate = calculateTimeToRotate(this.rotationTime);

if (this.rotate == true)
if (this.rotate == true) {
this.rotationTime = userPrefs.rotationTime || 0;
this.timeToRotate = calculateTimeToRotate(this.rotationTime);
this.initRotation(this.timeToRotate);
}
}
};

Expand Down Expand Up @@ -133,6 +143,8 @@ exports.DEBUG = 7;

Log.prototype = {
/**
* @author thakkar.rushikesh
* @param {Number} Number of milliseconds to wait before emitting `rotate` event.
* Initiates Log rotation timer. Emits `rotate` event after waiting till specified time.
*/
initRotation: function(waitTime) {
Expand Down

0 comments on commit f11f802

Please sign in to comment.