DateRollingFileStream.js 783 B

123456789101112131415161718192021222324252627282930313233
  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. if (options.daysToKeep) {
  16. options.numToKeep = options.daysToKeep;
  17. }
  18. if (pattern.startsWith('.')) {
  19. pattern = pattern.substring(1);
  20. }
  21. options.pattern = pattern;
  22. super(filename, options);
  23. this.mode = this.options.mode;
  24. }
  25. get theStream() {
  26. return this.currentFileStream;
  27. }
  28. }
  29. module.exports = DateRollingFileStream;