Skip to content

Commit

Permalink
Adding rotationFormat prop to file.js
Browse files Browse the repository at this point in the history
The goal of the rotation format property is to allow the user to pass a pointer to a function that will determine the format of the file name in case of a rotating logger (a logger with maxsize that generated files). 

sample usage:
this will make the files created under "log" to be named:
run<yyyyMMddhhmmss>.log

ex:
run20130629190056.log
run20130629190057.log
and so forth...
winston.add(winston.transports.File, { 
  filename: 'log/run.log',   
  maxsize: 150,
  rotationFormat: function() {
	return getFormattedDate();
	function getFormattedDate() {
    var temp = new Date();
    return dateStr = padStr(temp.getFullYear()) +
                  padStr(1 + temp.getMonth()) +
                  padStr(temp.getDate()) +
                  padStr(temp.getHours()) +
                  padStr(temp.getMinutes()) +
                  padStr(temp.getSeconds());    
	}
	function padStr(i) {
		return (i < 10) ? "0" + i : "" + i;
	}
  }
});
  • Loading branch information
orcaman committed Jun 29, 2013
1 parent 2c93353 commit a87a876
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/winston/transports/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var File = exports.File = function (options) {
this.json = options.json !== false;
this.colorize = options.colorize || false;
this.maxsize = options.maxsize || null;
this.rotationFormat = options.rotationFormat || false;
this.maxFiles = options.maxFiles || null;
this.prettyPrint = options.prettyPrint || false;
this.label = options.label || null;
Expand Down Expand Up @@ -565,7 +566,7 @@ File.prototype._getFile = function (inc) {
}

return this._created
? basename + this._created + ext
? basename + (this.rotationFormat ? this.rotationFormat() : this._created) + ext
: basename + ext;
};

Expand Down

0 comments on commit a87a876

Please sign in to comment.