Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: winstonjs/winston
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 101e2f45057ae16835bcc2f35ca00e77dd004465
Choose a base ref
...
head repository: winstonjs/winston
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 781686928016ec5cd9715a9434f58c795689f867
Choose a head ref
Loading
17 changes: 12 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -10,18 +10,25 @@ on:
- main
- master

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
Tests:
permissions:
contents: read # to fetch code (actions/checkout)
checks: write # to create new checks (coverallsapp/github-action)

runs-on: ubuntu-latest
strategy:
matrix:
node:
- 12
- 14
- 16
- 18
- 20
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install Dependencies
@@ -33,7 +40,7 @@ jobs:
- name: Test Coverage
run: npm run test:coverage
- name: Report test coverage to Coveralls.io
if: matrix.node == '16'
if: matrix.node == '20'
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .nycrc.yml
Original file line number Diff line number Diff line change
@@ -4,5 +4,5 @@ reporter:
check-coverage: true
branches: 61.51
lines: 70.85
functions: 73.21
statements: 70.54
functions: 70.00
statements: 70.54
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# CHANGELOG

## [v3.9.0](https://github.com/winstonjs/winston/compare/v3.8.2...v3.9.0)
### Functionality changes
* Handle undefined errors in getAllInfo in exception-handler in https://github.com/winstonjs/winston/pull/2208; thanks to new contributor @eivindrs
* fix: properly allow passing non-array transport in https://github.com/winstonjs/winston/pull/2256; thanks to new contributor @Tanuel
* fix #1732 (Http Transport uses JSON format options as request options) in https://github.com/winstonjs/winston/pull/2272; thanks to new contributor @MoritzLoewenstein (minor version bump per comment on the issue)
* fix: add guard clause to prevent FD leak in https://github.com/winstonjs/winston/pull/2301; thanks to new contributor @td-tomasz-joniec

### Dependency updates by @dependabot + CI autotesting
* Bump eslint from 8.23.0 to 8.32.0 by @dependabot in https://github.com/winstonjs/winston/pull/2209, https://github.com/winstonjs/winston/pull/2236, https://github.com/winstonjs/winston/pull/2258, & https://github.com/winstonjs/winston/pull/2271
* Bump @babel/core from 7.19.0 to 7.20.12 by @dependabot in https://github.com/winstonjs/winston/pull/2206, https://github.com/winstonjs/winston/pull/2234, https://github.com/winstonjs/winston/pull/2259, & https://github.com/winstonjs/winston/pull/2275
* Bump @types/node from 18.0.0 to 18.11.18 by @dependabot in https://github.com/winstonjs/winston/pull/2215, https://github.com/winstonjs/winston/pull/2235, & https://github.com/winstonjs/winston/pull/2264
* Bump @babel/preset-env from 7.19.0 to 7.20.2 by @dependabot in https://github.com/winstonjs/winston/pull/2218 & https://github.com/winstonjs/winston/pull/2244
* Bump safe-stable-stringify from 2.3.1 to 2.4.3 by @dependabot in https://github.com/winstonjs/winston/pull/2217 & https://github.com/winstonjs/winston/pull/2292
* Bump @babel/cli from 7.18.10 to 7.19.3 by @dependabot in https://github.com/winstonjs/winston/pull/2216
* Bump json5 from 2.2.1 to 2.2.3 by @dependabot in https://github.com/winstonjs/winston/pull/2260

### Documentation changes
* Fix readme typo in https://github.com/winstonjs/winston/pull/2230; thanks to new contributor @aretecode
* create new example for ready to use in https://github.com/winstonjs/winston/pull/2240; thanks to new contributor @myagizmaktav
* minor fixes to publishing.md

### Build Infrastructure changes
* GitHub Workflows security hardening in https://github.com/winstonjs/winston/pull/2252; thanks to new contributor @sashashura

## [v3.8.2](https://github.com/winstonjs/winston/compare/v3.8.1...v3.8.2)
### Patch-level changes
* Add `.js` to main entry point in package.json in https://github.com/winstonjs/winston/pull/2177; thanks to new contributor @rumanbsl
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -226,6 +226,7 @@ const logger = winston.createLogger({

const childLogger = logger.child({ requestId: '451' });
```
> `.child` is likely to be bugged if you're also extending the `Logger` class, due to some implementation details that make `this` keyword to point to unexpected things. Use with caution.
### Streams, `objectMode`, and `info` objects

@@ -674,10 +675,21 @@ To colorize the standard logging level add
```js
winston.format.combine(
winston.format.colorize(),
winston.format.json()
winston.format.simple()
);
```
where `winston.format.simple()` is whatever other formatter you want to use. The `colorize` formatter must come before any formatters adding text you wish to color.

### Colorizing full log line when json formatting logs

To colorize the full log line with the json formatter you can apply the following

```js
winston.format.combine(
winston.format.json(),
winston.format.colorize({ all })
);
```
where `winston.format.json()` is whatever other formatter you want to use. The `colorize` formatter must come before any formatters adding text you wish to color.

## Transports

@@ -764,11 +776,11 @@ const logger = winston.createLogger({
level: 'error',
format: winston.format.json()
}),
new transports.Http({
new winston.transports.Http({
level: 'warn',
format: winston.format.json()
}),
new transports.Console({
new winston.transports.Console({
level: 'info',
format: winston.format.combine(
winston.format.colorize(),
@@ -898,7 +910,7 @@ logger.exitOnError = ignoreEpipe;

### Handling Uncaught Promise Rejections with winston

With `winston`, it is possible to catch and log `uncaughtRejection` events
With `winston`, it is possible to catch and log `unhandledRejection` events
from your process. With your own logger instance you can enable this behavior
when it's created or later on in your applications lifecycle:

@@ -969,7 +981,7 @@ setTimeout(function () {
}, 1000);
```

Also you can start a timer and keep a reference that you can call `.done()``
Also you can start a timer and keep a reference that you can call `.done()`
on:

``` js
4 changes: 2 additions & 2 deletions docs/publishing.md
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ The release process here mostly follows along with the [vbump script](https://gi
1. Paste the same version number, with or without the v (with is probably better) in the release title box.
1. Click 'Generate release notes' and cut & paste the draft contents into the changelog.
1. Paste the contents of the changelog for this release in the 'Describe this release' box.
1. Check to make sure you've caught everything using GitHub's compare tool ([example here](https://github.com/winstonjs/winston/compare/v3.6.0...master)).
1. Check to make sure you've caught everything (including direct commits) using GitHub's compare tool ([example here](https://github.com/winstonjs/winston/compare/v3.6.0...master)).
1. Update the changelog. It's nice to thank the contributors here. It's nice to organize this by which changes would merit which level of semver bump, and especially call out any breaking changes (major-version-number) concisely at the start.
1. **Update the version number in package.json and package-lock.json**, bumping as appropriate for [semver](https://semver.org/) based on the most significant position change trigger from the changelog you just wrote/reviewed. Do not miss this step! Also note there are two places in package-lock where this ges updated: at the top level and under the empty-string entry of packages.
1. **Update the version number in package.json and package-lock.json**, bumping as appropriate for [semver](https://semver.org/) based on the most significant position change trigger from the changelog you just wrote/reviewed. Do not miss this step! Also note there are two places in package-lock where this gets updated: at the top level and under the empty-string entry of packages.
1. Update the tag and version number on the Draft a New Release page, with the same number (which might've changed while drafting changelog notes).
1. Make sure your local master branch is up to date.
1. Make sure all the lint checks and tests pass, beyond what the CI might've told you.
62 changes: 52 additions & 10 deletions docs/transports.md
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ there are additional transports written by
* [Logsene](#logsene-transport) (including Log-Alerts and Anomaly Detection)
* [Logz.io](#logzio-transport)
* [Mail](#mail-transport)
* [Newrelic](#newrelic-transport) (errors only)
* [New Relic](#new-relic-agent-transport)
* [Papertrail](#papertrail-transport)
* [PostgresQL](#postgresql-transport)
* [Pusher](#pusher-transport)
@@ -59,6 +59,7 @@ there are additional transports written by
* [SQLite3](#sqlite3-transport)
* [SSE with KOA 2](#sse-transport-with-koa-2)
* [Sumo Logic](#sumo-logic-transport)
* [VS Code extension](#vs-code-extension)
* [Worker Thread based async Console transport](#worker-thread-based-async-console-transport)
* [Winlog2 Transport](#winlog2-transport)

@@ -102,6 +103,7 @@ looking for daily log rotation see [DailyRotateFile](#dailyrotatefile-transport)
* __level:__ Level of messages that this transport should log (default: level set on parent logger).
* __silent:__ Boolean flag indicating whether to suppress output (default false).
* __eol:__ Line-ending character to use. (default: `os.EOL`).
* __lazy:__ If true, log files will be created on demand, not at the initialization time.
* __filename:__ The filename of the logfile to write output to.
* __maxsize:__ Max size in bytes of the logfile, if the size is exceeded then a new file is created, a counter will become a suffix of the log file.
* __maxFiles:__ Limit the number of files created when the size of the logfile is exceeded.
@@ -639,21 +641,26 @@ The Mail transport uses [node-mail][17] behind the scenes. Options are the foll

*Metadata:* Stringified as JSON in email.

### Newrelic Transport
### New Relic Agent Transport

[newrelic-winston][23] is a Newrelic transport:
[winston-newrelic-agent-transport][47] is a New Relic transport that leverages the New Relic agent:

``` js
const winston = require('winston');
const Newrelic = require('newrelic-winston');
logger.add(new Newrelic(options));
import winston from 'winston'
import NewrelicTransport from 'winston-newrelic-agent-transport'

const logger = winston.createLogger()

const options = {}
logger.add(new NewrelicTransport(options))
```

The Newrelic transport will send your errors to newrelic and accepts the follwing optins:
The New Relic agent typically automatically forwards Winston logs to New Relic when using CommonJS. With CommonJS no additional transport should be needed. However, when using ECMAScript modules, the automatic forwarding of logs can with certain coding patterns not work. If the New Relic agent is not automatically forwarding your logs, this transport provides a solution.

* __env__: the current evironment. Defatuls to `process.env.NODE_ENV`
Options:

If `env` is either 'dev' or 'test' the lib will _not_ load the included newrelic module saving devs from anoying errors ;)
* __level__ (optional): The Winston logging level to use as the maximum level of messages that the transport will log.
* __rejectCriteria__ (optional): The rejectCriteria option allows you to specify an array of regexes that will be matched against either the Winston info object or log message to determine whether or not a log message should be rejected and not logged to New Relic.

### Papertrail Transport

@@ -826,6 +833,40 @@ Options:
### SSE transport with KOA 2
[winston-koa-sse](https://github.com/alexvictoor/winston-koa-sse) is a transport that leverages on Server Sent Event. With this transport you can use your browser console to view your server logs.

### VS Code extension

[winston-transport-vscode][48] is a transport for VS Code extension development.

```js
const vscode = require('vscode');
const winston = require('winston');
const { OutputChannelTransport } = require('winston-transport-vscode');

const outputChannel = vscode.window.createOutputChannel('My extension');

const logger = winston.createLogger({
transports: [new OutputChannelTransport({ outputChannel })],
});
```

The extension includes dedicated log levels and format for using with VS Code's
LogOutputChannel.

```js
const { LogOutputChannelTransport } = require('winston-transport-vscode');

const outputChannel = vscode.window.createOutputChannel('My extension', {
log: true,
});

const logger = winston.createLogger({
levels: LogOutputChannelTransport.config.levels,
format: LogOutputChannelTransport.format(),
transports: [new LogOutputChannelTransport({ outputChannel })],
});
```


### Worker Thread based async Console transport

[winston-console-transport-in-worker][46]
@@ -985,7 +1026,6 @@ That's why we say it's a logger for just about everything
[20]: https://github.com/jorgebay/winston-cassandra
[21]: https://github.com/jpoon/winston-azuretable
[22]: https://github.com/rickcraig/winston-airbrake2
[23]: https://github.com/namshi/winston-newrelic
[24]: https://github.com/sematext/winston-logsene
[25]: https://github.com/timdp/winston-aws-cloudwatch
[26]: https://github.com/lazywithclass/winston-cloudwatch
@@ -1009,3 +1049,5 @@ That's why we say it's a logger for just about everything
[44]: https://github.com/Quintinity/humio-winston
[45]: https://github.com/datalust/winston-seq
[46]: https://github.com/arpad1337/winston-console-transport-in-worker
[47]: https://github.com/kimnetics/winston-newrelic-agent-transport
[48]: https://github.com/loderunner/winston-transport-vscode
112 changes: 112 additions & 0 deletions examples/ready-to-use-pattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
const winston = require('../');

const config = {
levels: {
error: 0,
debug: 1,
warn: 2,
data: 3,
info: 4,
verbose: 5,
silly: 6
},
colors: {
error: 'red',
debug: 'blue',
warn: 'yellow',
data: 'magenta',
info: 'green',
verbose: 'cyan',
silly: 'grey'
}
};

winston.addColors(config.colors);
const wLogger = (input: { logName: string; level: string }): winston.Logger =>
winston.createLogger({
levels: config.levels,
level: `${input.level}`,
transports: [
new winston.transports.Console({
level: `${input.level}`,

format: winston.format.combine(
winston.format.timestamp(),
winston.format.printf(
info =>
// https://stackoverflow.com/a/69044670/20358783 more detailLocaleString
`${new Date(info.timestamp).toLocaleDateString('tr-Tr', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})} ${info.level.toLocaleUpperCase()}: ${info.message}`
),
winston.format.colorize({ all: true })
)
}),
new winston.transports.File({
filename: `./src/logs/${input.logName}/${input.logName}-Error.log`,
level: 'error',
format: winston.format.printf(
info =>
`${new Date(info.timestamp).toLocaleDateString('tr-Tr', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})} ${info.level.toLocaleUpperCase()}: ${info.message}`
)
}),
new winston.transports.File({
filename: `./src/logs/${input.logName}/${input.logName}-Warn.log`,
level: 'warn',
format: winston.format.printf(
info =>
`${new Date(info.timestamp).toLocaleDateString('tr-Tr', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})} ${info.level.toLocaleUpperCase()}: ${info.message}`
)
}),
new winston.transports.File({
filename: `./src/logs/${input.logName}/${input.logName}-All.log`,
level: 'silly',
format: winston.format.printf(
info =>
`${new Date(info.timestamp).toLocaleDateString('tr-Tr', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})} ${info.level.toLocaleUpperCase()}: ${info.message}`
)
}),

new winston.transports.File({
format: winston.format.printf(
info =>
`${new Date(info.timestamp).toLocaleDateString('tr-Tr', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})} ${info.level.toLocaleUpperCase()}: ${info.message}`
),
filename: './src/logs/globalLog.log',
level: 'silly'
})
]
});

export default wLogger;

//const logger = wLogger({ logName: moduleName, level: logLevel })
//logger.info('test')
Loading