Permalink
Browse files

Refactored constructor, Added api-doc comments.

  • Loading branch information...
1 parent c4f9bc2 commit f11f8020e5000605ab37ff83ef09e401857f0f2d @thakkar-rushikesh committed Apr 6, 2012
Showing with 19 additions and 7 deletions.
  1. +19 −7 lib/log.js
View
@@ -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) {
@@ -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()];
@@ -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);
+ }
}
};
@@ -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) {

0 comments on commit f11f802

Please sign in to comment.