Socket
Socket
Sign inDemoInstall

winston

Package Overview
Dependencies
36
Maintainers
6
Versions
82
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 3.1.0

test/transports/file-tailrolling.test.js

23

CHANGELOG.md
# CHANGELOG
## v3.0.1 / 2018-09-04
### NPMIGNORE IS HARD EDITION
## v3.1.0 / 2018-08-22
### RELEASES ON A PLANE EDITION
- (@DABH) npm ignore scratch folder from CI.
- Minor TypeScript fixes [#1362], [#1395], [#1440]
- Fix minor typos [#1359], [#1363], [#1372], [#1378], [#1390]
- [#1373], (@revik): Add `consoleWarnLevels` property to console transport options for `console.warn` browser support.
- [#1394], (@bzoz): Fix tests on Windows.
- [#1447], (@dboshardy): Support transport name option to override default names for built-in transports.
- [#1420], (@ledbit): Fix file rotation with `tailing: true` (Fixes [#1450], [#1194]).
- [#1352], (@lutovich): Add `isLevelEnabled(string)` & `isXXXEnabled()` to `Logger` class.
- Dependency management
- Regenerate `package-lock.json`.
- Upgrade to `colors@^1.3.2` (Fixes [#1439]).
- Upgrade to `logform@^1.9.1`.
- Upgrade to `diagnostics@^1.1.1`.
- Upgrade to `@types/node@^10.9.3`.
- Upgrade to `assume@^2.1.0`.
- Upgrade to `hock@^1.3.3`.
- Upgrade to `mocha@^5.2.0`.
- Upgrade to `nyc@^13.0.1`.
- Upgrade to `split2@^3.0.0`.

@@ -8,0 +25,0 @@ ## v3.0.0 / 2018-06-12

13

index.d.ts

@@ -48,3 +48,3 @@ // Type definitions for winston 3.0

start: Date;
done(): boolean;
done(info?: any): boolean;
}

@@ -132,4 +132,11 @@

interface Container {
loggers: object;
options: object;
loggers: Map<string, Logger>;
options: LoggerOptions;
add(id: string, options?: LoggerOptions): Logger;
get(id: string, options?: LoggerOptions): Logger;
has(id: string): boolean;
close(id?: string): void;
new(options?: LoggerOptions): Container;
}

@@ -136,0 +143,0 @@

@@ -47,3 +47,3 @@ /**

// Define prototype methods for each log level
// e.g. logger.log('info', msg) <––> logger.info(msg)
// e.g. logger.log('info', msg) <––> logger.info(msg) & logger.isInfoEnabled()
this[level] = (...args) => {

@@ -65,2 +65,4 @@ // Optimize the hot-path which is the single object.

};
this[isLevelEnabledFunctionName(level)] = () => this.isLevelEnabled(level);
});

@@ -70,2 +72,6 @@ }

function isLevelEnabledFunctionName(level) {
return 'is' + level.charAt(0).toUpperCase() + level.slice(1) + 'Enabled';
}
/**

@@ -72,0 +78,0 @@ * Create a new instance of a winston Logger. Creates a new

@@ -98,2 +98,27 @@ /**

isLevelEnabled(level) {
const givenLevelValue = getLevelValue(this.levels, level);
if (givenLevelValue === null) {
return false;
}
const configuredLevelValue = getLevelValue(this.levels, this.level);
if (configuredLevelValue === null) {
return false;
}
if (!this.transports || this.transports.length === 0) {
return configuredLevelValue >= givenLevelValue;
}
const index = this.transports.findIndex(transport => {
let transportLevelValue = getLevelValue(this.levels, transport.level);
if (transportLevelValue === null) {
transportLevelValue = configuredLevelValue;
}
return transportLevelValue >= givenLevelValue;
});
return index !== -1;
}
/* eslint-disable valid-jsdoc */

@@ -480,3 +505,3 @@ /**

// eslint-disable-next-line no-console
console.warn('Deprecated: .unhandleExceptions() will be removed in winston@4. Use .unexceptions.handle()');
console.warn('Deprecated: .unhandleExceptions() will be removed in winston@4. Use .exceptions.unhandle()');
this.exceptions.unhandle(...args);

@@ -516,2 +541,10 @@ }

function getLevelValue(levels, level) {
const value = levels[level];
if (!value && value !== 0) {
return null;
}
return value;
}
/**

@@ -518,0 +551,0 @@ * Represents the current readableState pipe targets for this Logger instance.

@@ -30,4 +30,5 @@ /* eslint-disable no-console */

// Expose the name of this Transport on the prototype
this.name = 'console';
this.name = options.name || 'console';
this.stderrLevels = this._stringArrayToSet(options.stderrLevels);
this.consoleWarnLevels = this._stringArrayToSet(options.consoleWarnLevels);
this.eol = options.eol || os.EOL;

@@ -59,2 +60,16 @@ }

return;
} else if (this.consoleWarnLevels[info[LEVEL]]) {
if (console._stderr) {
// Node.js maps `process.stderr` to `console._stderr`.
// in Node.js console.warn is an alias for console.error
console._stderr.write(`${info[MESSAGE]}${this.eol}`);
} else {
// console.warn adds a newline
console.warn(info[MESSAGE]);
}
if (callback) {
callback(); // eslint-disable-line callback-return
}
return;
}

@@ -61,0 +76,0 @@

@@ -36,3 +36,3 @@ /**

// Expose the name of this Transport on the prototype.
this.name = 'file';
this.name = options.name || 'file';

@@ -598,17 +598,15 @@ // Helper function which throws an `Error` in the event that any of the

const isZipped = this.zippedArchive ? '.gz' : '';
for (let x = this.maxFiles - 1; x > 0; x--) {
tasks.push(function (i) {
return cb => {
let fileName = `${basename}${(i - 1)}${ext}${isZipped}`;
const tmppath = path.join(this.dirname, fileName);
for (let x = this.maxFiles - 1; x > 1; x--) {
tasks.push(function (i, cb) {
let fileName = `${basename}${(i - 1)}${ext}${isZipped}`;
const tmppath = path.join(this.dirname, fileName);
fs.exists(tmppath, exists => {
if (!exists) {
return cb(null);
}
fs.exists(tmppath, exists => {
if (!exists) {
return cb(null);
}
fileName = `${basename}${i}${ext}${isZipped}`;
fs.rename(tmppath, path.join(this.dirname, fileName), cb);
});
};
fileName = `${basename}${i}${ext}${isZipped}`;
fs.rename(tmppath, path.join(this.dirname, fileName), cb);
});
}.bind(this, x));

@@ -620,3 +618,3 @@ }

path.join(this.dirname, `${basename}${ext}`),
path.join(this.dirname, `${basename}1${ext}`),
path.join(this.dirname, `${basename}1${ext}${isZipped}`),
callback

@@ -623,0 +621,0 @@ );

@@ -29,3 +29,3 @@ /**

this.name = 'http';
this.name = options.name || 'http';
this.ssl = !!options.ssl;

@@ -32,0 +32,0 @@ this.host = options.host || 'localhost';

{
"name": "winston",
"description": "A logger for just about everything.",
"version": "3.0.1",
"version": "3.1.0",
"author": "Charlie Robbins <charlie.robbins@gmail.com>",

@@ -30,5 +30,5 @@ "maintainers": [

"async": "^2.6.0",
"diagnostics": "^1.0.1",
"diagnostics": "^1.1.1",
"is-stream": "^1.1.0",
"logform": "^1.9.0",
"logform": "^1.9.1",
"one-time": "0.0.4",

@@ -41,13 +41,13 @@ "readable-stream": "^2.3.6",

"devDependencies": {
"@types/node": "^9.6.6",
"@types/node": "^10.9.3",
"abstract-winston-transport": ">= 0.5.1",
"assume": "^2.0.1",
"colors": "^1.2.0",
"assume": "^2.1.0",
"colors": "^1.3.2",
"cross-spawn-async": "^2.0.0",
"eslint-config-populist": "^4.1.0",
"hock": "^1.3.2",
"mocha": "^3.2.0",
"nyc": "^11.2.1",
"hock": "^1.3.3",
"mocha": "^5.2.0",
"nyc": "^13.0.1",
"rimraf": "^2.6.2",
"split2": "^2.1.1",
"split2": "^3.0.0",
"std-mocks": "^1.0.0",

@@ -58,2 +58,3 @@ "through2": "^2.0.0",

"main": "./lib/winston",
"types": "./index.d.ts",
"scripts": {

@@ -63,3 +64,3 @@ "lint": "populist lib/*.js lib/winston/*.js lib/winston/**/*.js",

"test": "nyc --reporter=text --reporter lcov npm run test:mocha",
"test:mocha": "mocha test/*.test.js test/**/*.test.js"
"test:mocha": "mocha test/*.test.js test/**/*.test.js --exit"
},

@@ -66,0 +67,0 @@ "engines": {

@@ -133,5 +133,5 @@ # winston

| ------------- | ---------------------- | --------------- |
| `level` | `'info'` | Log only if `info.level` less than or equal to this level |
| `level` | `'info'` | Log only if [`info.level`](#streams-objectmode-and-info-objects) less than or equal to this level |
| `levels` | `winston.config.npm` | Levels (and colors) representing log priorities |
| `format` | `winston.formats.json` | Formatting for `info` messages (see: [Formats]) |
| `format` | `winston.format.json` | Formatting for `info` messages (see: [Formats]) |
| `transports` | `[]` _(No transports)_ | Set of logging targets for `info` messages |

@@ -198,5 +198,6 @@ | `exitOnError` | `true` | If false, handled exceptions will not cause `process.exit` |

In `winston`, both `Logger` and `Transport` instances are treated as
`objectMode` streams that accept an `info` object. The `info`
object represents a single log message. The object itself is mutable. Every
`info` must have at least the `level` and `message` properties:
[`objectMode`](https://nodejs.org/api/stream.html#stream_object_mode)
streams that accept an `info` object. The `info` object represents a
single log message. The object itself is mutable. Every `info` must
have at least the `level` and `message` properties:

@@ -309,3 +310,3 @@ ``` js

// info: test message my 123 {}
// info: test message 123 {}
logger.log('info', 'test message %d', 123);

@@ -325,3 +326,3 @@

// Ignore log messages if the have { private: true }
// Ignore log messages if they have { private: true }
const ignorePrivate = format((info, opts) => {

@@ -827,6 +828,9 @@ if (info.private) { return false; }

All profile messages are set to 'info' level by default and both message and
metadata are optional. There are no plans in the Roadmap to make this
configurable, but we are open to suggestions through new issues!
All profile messages are set to 'info' level by default, and both message and
metadata are optional. For individual profile messages, you can override the default log level by supplying a metadata object with a `level` property:
```js
logger.profile('test', { level: 'debug' });
```
## Querying Logs

@@ -920,3 +924,3 @@

process. Each instance of `winston.Logger` is also a [Node.js stream]. A
`finished` event will be raised when all logs have flushed to all transports
`finish` event will be raised when all logs have flushed to all transports
after the stream has been ended.

@@ -923,0 +927,0 @@

@@ -26,4 +26,8 @@ /*

let testDone = false;
before(removeFixtures);
after(removeFixtures);
after(done => {
testDone = true;
removeFixtures(done);
});

@@ -105,2 +109,4 @@ it('should create multiple files correctly when passed more than the maxsize', function (done) {

maxsizeTransport.on('open', function (file) {
if (testDone) return; // ignore future notifications
const match = file.match(/(\d+)\.log$/);

@@ -107,0 +113,0 @@ const count = match ? match[1] : 0;

@@ -23,4 +23,7 @@ 'use strict';

stderrLevels: new winston.transports.Console({
stderrLevels: ['info', 'warn']
stderrLevels: ['info', 'error']
}),
consoleWarnLevels: new winston.transports.Console({
consoleWarnLevels: ['warn', 'debug']
}),
eol: new winston.transports.Console({ eol: 'X' }),

@@ -44,15 +47,18 @@ syslog: new winston.transports.Console({

* Returns a function that asserts the `transport` has the specified
* `stderrLevels`.
* logLevels values in the appropriate logLevelsName member.
*
* @param {TransportStream} transport Transport to assert against
* @param {Array} stderrLevels Set of levels assumed to exist
* @param {Array} logLevels Set of levels assumed to exist for the specified map
* @param {String} logLevelsName The name of the array/map that holdes the log leveles values (ie: 'stderrLevels', 'consoleWarnLevels')
* @return {function} Assertion function to execute comparison
*/
function assertStderrLevels(transport, stderrLevels) {
function assertLogLevelsValues(transport, logLevels, logLevelsName = 'stderrLevels') {
return function () {
assume(JSON.stringify(Object.keys(transport.stderrLevels).sort()))
.equals(JSON.stringify(stderrLevels.sort()));
assume(JSON.stringify(Object.keys(transport[logLevelsName]).sort()))
.equals(JSON.stringify(logLevels.sort()));
};
}
describe('Console transport', function () {

@@ -83,5 +89,6 @@ describe('with defaults', function () {

it("should set stderrLevels to [] by default", assertStderrLevels(
it("should set stderrLevels to [] by default", assertLogLevelsValues(
transports.defaults,
[]
[],
'stderrLevels'
));

@@ -108,6 +115,12 @@ });

it("{ stderrLevels: ['info', 'warn'] } logs to them appropriately", assertStderrLevels(
it("{ stderrLevels: ['info', 'error'] } logs to them appropriately", assertLogLevelsValues(
transports.stderrLevels,
['info', 'warn']
['info', 'error'],
'stderrLevels'
));
it("{ consoleWarnLevels: ['warn', 'debug'] } logs to them appropriately", assertLogLevelsValues(
transports.consoleWarnLevels,
['warn', 'debug'],
'consoleWarnLevels'
));

@@ -114,0 +127,0 @@ it('{ eol } adds a custom EOL delimiter', function (done) {

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc