Socket
Socket
Sign inDemoInstall

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 4.5.5 to 4.6.0

.github/workflows/unit-tests.yml

9

daily-rotate-file.js

@@ -93,3 +93,4 @@ 'use strict';

create_symlink: options.createSymlink ? options.createSymlink : false,
symlink_name: options.symlinkName ? options.symlinkName : 'current.log'
symlink_name: options.symlinkName ? options.symlinkName : 'current.log',
watch_log: options.watchLog ? options.watchLog : false
});

@@ -145,2 +146,8 @@

}
if (options.watchLog) {
this.logStream.on('addWatcher', (newFile) => {
self.emit('addWatcher', newFile);
})
}
}

@@ -147,0 +154,0 @@ };

@@ -97,2 +97,7 @@ import TransportStream = require("winston-transport");

/**
* Watch the current file being written to and recreate it in case of accidental deletion. (default: FALSE)
*/
watchLog?: boolean;
handleRejections?: boolean;

@@ -99,0 +104,0 @@ }

19

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

@@ -8,6 +8,6 @@ "main": "index.js",

"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "mocha && eslint .",
"test": "mocha --ignore **/*.worker.js && eslint .",
"preversion": "npm test",

@@ -37,10 +37,11 @@ "postversion": "git push && git push --tags && npm publish"

"chai": "4.2.0",
"eslint": "^6.0.1",
"eslint-plugin-node": "^11.0.0",
"mocha": "^7.1.1",
"moment": "^2.24.0",
"rimraf": "^3.0.2"
"eslint": "^8.5.0",
"eslint-plugin-node": "^11.1.0",
"mocha": "^9.1.3",
"moment": "^2.29.1",
"rimraf": "^3.0.2",
"threads": "^1.7.0"
},
"dependencies": {
"file-stream-rotator": "^0.5.7",
"file-stream-rotator": "^0.6.1",
"object-hash": "^2.0.1",

@@ -47,0 +48,0 @@ "triple-beam": "^1.3.0",

# winston-daily-rotate-file
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
[![NPM version][npm-image]][npm-url]

@@ -29,3 +29,3 @@ [![NPM](https://nodei.co/npm/winston-daily-rotate-file.png)](https://nodei.co/npm/winston-daily-rotate-file/)

* **maxSize:** Maximum size of the file after which it will rotate. This can be a number of bytes, or units of kb, mb, and gb. If using the units, add 'k', 'm', or 'g' as the suffix. The units need to directly follow the number. (default: null)
* **maxFiles:** Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null)
* **maxFiles:** Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. It uses auditFile to keep track of the log files in a json format. It won't delete any file not contained in it. It can be a number of files or number of days (default: null)
* **options:** An object resembling https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options indicating additional options that should be passed to the file stream. (default: `{ flags: 'a' }`)

@@ -62,4 +62,62 @@ * **auditFile**: A string representing the name of the audit file. This can be used to override the default filename which is generated by computing a hash of the options object. (default: '.<optionsHash>.json')

logger.info('Hello World!');
```
### ES6
``` js
import * as winston from 'winston';
import 'winston-daily-rotate-file';
const transport = new winston.transports.DailyRotateFile({
filename: 'application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
transport.on('rotate', function(oldFilename, newFilename) {
// do something fun
});
const logger = winston.createLogger({
transports: [
transport
]
});
logger.info('Hello World!');
```
### Typescript
``` typescript
import * as winston from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';
const transport: DailyRotateFile = new DailyRotateFile({
filename: 'application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
transport.on('rotate', function(oldFilename, newFilename) {
// do something fun
});
const logger = winston.createLogger({
transports: [
transport
]});
logger.info('Hello World!');
```
This transport emits the following custom events:

@@ -80,5 +138,1 @@

[npm-url]: https://npmjs.org/package/winston-daily-rotate-file
[travis-image]: https://travis-ci.org/winstonjs/winston-daily-rotate-file.svg?branch=master
[travis-url]: https://travis-ci.org/winstonjs/winston-daily-rotate-file
[daviddm-image]: https://david-dm.org/winstonjs/winston-daily-rotate-file.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/winstonjs/winston-daily-rotate-file

@@ -10,2 +10,5 @@ /* eslint-disable max-nested-callbacks,no-unused-expressions,handle-callback-err */

var winston = require('winston');
// eslint-disable-next-line node/no-unpublished-require -- It's published, see: https://threads.js.org/
var { spawn, Thread, Worker } = require('threads');
var { promisify } = require('util');
var MemoryStream = require('./memory-stream');

@@ -16,6 +19,2 @@ var randomString = require('./random-string');

function sendLogItem(transport, level, message, meta, cb) { // eslint-disable-line max-params
var logger = winston.createLogger({
transports: [transport]
});
transport.on('logged', function () {

@@ -27,6 +26,4 @@ if (cb) {

logger.info({
level: level,
message: message
});
const info = { level: level, message: message };
transport.log(winston.format.json().transform(info));
}

@@ -38,3 +35,2 @@

this.transport = new DailyRotateFile({
json: true,
stream: this.stream

@@ -82,25 +78,2 @@ });

describe('when passed metadata', function () {
var circular = {};
circular.metadata = circular;
var params = {
no: {},
object: {metadata: true},
primitive: 'metadata',
circular: circular
};
Object.keys(params).forEach(function (param) {
it('should accept log messages with ' + param + ' metadata', function (done) {
sendLogItem(this.transport, 'info', 'test log message', params[param], function (err, logged) {
expect(err).to.be.null;
expect(logged).to.be.true;
// TODO parse the metadata value to make sure its set properly
done();
});
});
});
});
describe('when using a filename or dirname', function () {

@@ -128,3 +101,3 @@ var logDir = path.join(__dirname, 'logs');

it('should write to the file', function (done) {
this.transport.on('finish', function () {
const finishListener = () => {
var logEntries = fs.readFileSync(filename).toString().split('\n').slice(0, -1);

@@ -137,4 +110,8 @@ expect(logEntries.length).to.equal(1);

done();
});
this.transport.removeListener('finish', finishListener)
}
this.transport.on('finish', finishListener);
sendLogItem(this.transport, 'info', 'this message should write to the file', {}, function (err, logged) {

@@ -192,3 +169,3 @@ expect(err).to.be.null;

this.transport.on('finish', function () {
const finishListener = () => {
fs.readdir(logDir, function (err, files) {

@@ -200,3 +177,7 @@ expect(files.filter(function (file) {

});
});
this.transport.removeListener('finish', finishListener)
}
this.transport.on('finish', finishListener);
sendLogItem(this.transport, 'info', randomString(1056));

@@ -208,2 +189,22 @@ sendLogItem(this.transport, 'info', randomString(1056));

describe('when setting watchLog', function () {
it('should addWatcher to recreate log if deleted', function (done) {
var opts = Object.assign({}, options);
opts.watchLog = true;
this.transport = new DailyRotateFile(opts);
this.transport.on('addWatcher', (newFile) => {
expect(newFile).to.equal(filename);
done()
});
this.transport.on('new', (newFile) => {
expect(newFile).to.equal(filename);
});
sendLogItem(this.transport, 'info', 'First message to file');
this.transport.close();
});
});
describe('query', function () {

@@ -240,3 +241,3 @@ it('should call callback when no files are present', function () {

var self = this;
this.transport.on('finish', function () {
const finishListener = () => {
self.transport.query(function (err, results) {

@@ -247,3 +248,6 @@ expect(results).to.not.be.null;

});
});
this.transport.removeListener('finish', finishListener)
}
this.transport.on('finish', finishListener);

@@ -274,3 +278,17 @@ this.transport.close();

});
describe('concurrent', () => {
it('should not throw EEXIST', async () => {
const logDir = path.join(__dirname, 'concurrent-logs');
await promisify(rimraf)(logDir);
const workers = await Promise.all([
spawn(new Worker('./transport.worker.js')),
spawn(new Worker('./transport.worker.js')),
spawn(new Worker('./transport.worker.js')),
]);
await Promise.all(workers.map(worker => worker.run()));
await Promise.all(workers.map(worker => Thread.terminate(worker)));
})
})
});
});

Sorry, the diff of this file is not supported yet

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