Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding rotationFormat prop to file.js #273

Merged
merged 1 commit into from Dec 30, 2014
Merged

Conversation

orcaman
Copy link
Contributor

@orcaman orcaman commented Jun 29, 2013

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.log

so these would be files created today:

run20130629190056.log
run20130629190057.log
and so forth...

sample code:

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;
    }
  }
});

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;
	}
  }
});
@indexzero
Copy link
Member

Not opposed but it needs tests and documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants