DateRollingFileStream.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const RollingFileWriteStream = require('./RollingFileWriteStream');
  2. // just to adapt the previous version
  3. class DateRollingFileStream extends RollingFileWriteStream {
  4. constructor(filename, pattern, options) {
  5. if (pattern && typeof(pattern) === 'object') {
  6. options = pattern;
  7. pattern = null;
  8. }
  9. if (!options) {
  10. options = {};
  11. }
  12. if (!pattern) {
  13. pattern = 'yyyy-MM-dd';
  14. }
  15. options.pattern = pattern;
  16. if (!options.numBackups && options.numBackups !== 0) {
  17. if (!options.daysToKeep && options.daysToKeep !== 0) {
  18. options.daysToKeep = 1;
  19. } else {
  20. process.emitWarning(
  21. "options.daysToKeep is deprecated due the confusion it causes when used " +
  22. "together with file size rolling. Please use options.numBackups instead.",
  23. "DeprecationWarning", "StreamRoller0001"
  24. );
  25. }
  26. options.numBackups = options.daysToKeep;
  27. } else {
  28. options.daysToKeep = options.numBackups;
  29. }
  30. super(filename, options);
  31. this.mode = this.options.mode;
  32. }
  33. get theStream() {
  34. return this.currentFileStream;
  35. }
  36. }
  37. module.exports = DateRollingFileStream;