Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

winston-daily-rotate-file

Package Overview
Dependencies
Maintainers
2
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

winston-daily-rotate-file - npm Package Compare versions

Comparing version 1.4.6 to 1.5.0

test.js.txt

52

index.js

@@ -83,2 +83,3 @@ 'use strict';

this.zippedArchive = options.zippedArchive || false;
this.maxDays = options.maxDays || 0;

@@ -441,2 +442,3 @@ if (this.json) {

this._filenameHasExpired()) {
this._cleanOldFiles();
//

@@ -777,1 +779,51 @@ // If we dont have a stream or have exceeded our size, then create

};
// ### @private function _cleanOldFiles ()
// Remove old log files
// based on "maxDays" option
DailyRotateFile.prototype._cleanOldFiles = function () {
var self = this;
var millisecondsInDay = 86400000;
var now = Date.now();
function removeOldFile(file) {
fs.unlink(self.dirname + path.sep + file, function (errUnlink) {
if (errUnlink) {
console.error('Error removing file ', file);
}
});
}
function tryToRemoveLogFile(file) {
var completeFileName = self.dirname + path.sep + file;
fs.stat(completeFileName, function (errStats, stats) {
if (errStats) {
console.error('Error stats file ', file, errStats);
return;
}
var lastChangeTimestamp = ((stats.mtime && stats.mtime.getTime()) || 0);
var lifeTime = now - lastChangeTimestamp;
if (stats.isFile() && lifeTime > (millisecondsInDay * self.maxDays)) {
removeOldFile(file);
}
});
}
// if not maxDays specified, do not remove old log files
if (self.maxDays) {
fs.readdir(self.dirname, function (err, files) {
if (err) {
console.error('Error reading directory ', self.dirname, err);
return;
}
var fileNameReg = new RegExp(self._basename, 'g');
files.forEach(function (file) {
if (/.log/.test(file) && fileNameReg.test(file)) {
tryToRemoveLogFile(file);
}
});
});
}
};

2

package.json
{
"name": "winston-daily-rotate-file",
"version": "1.4.6",
"version": "1.5.0",
"description": "A transport for winston which logs to a rotating file each day.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -12,4 +12,4 @@ # winston-daily-rotate-file

require('winston-daily-rotate-file');
var transport = new winston.transports.DailyRotateFile({
var transport = new (winston.transports.DailyRotateFile)({
filename: './log',

@@ -20,3 +20,3 @@ datePattern: 'yyyy-MM-dd.',

});
var logger = new (winston.Logger)({

@@ -37,2 +37,3 @@ transports: [

* __zippedArchive:__ A boolean to define whether or not to gzip archived log files (default 'false').
* __maxDays:__ A number representing the maximum number of days a log file will be saved. Any log file older than this specified number of days will be removed. If not value or a 0, no log files will be removed.

@@ -39,0 +40,0 @@ Valid meta characters in the datePattern are:

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc