Skip to content

Commit ae6ba2d

Browse files
authored
Prepare 5.0.0 (#389)
* Prevent crash in bad timing cases Resolves error cases like ``` ENOENT: no such file or directory, unlink '/opt/iobroker/log/iobroker.2023-01-04.log' Error: ENOENT: no such file or directory, unlink '/opt/iobroker/log/iobroker.2023-01-04.log' at Object.unlinkSync (node:fs:1767:3) at WriteStream.<anonymous> (/opt/iobroker/node_modules/winston-daily-rotate-file/daily-rotate-file.js:140:28) at WriteStream.emit (node:events:525:35) at WriteStream.emit (node:domain:489:12) at finish (node:internal/streams/writable:756:10) at finishMaybe (node:internal/streams/writable:741:9) at afterWrite (node:internal/streams/writable:506:3) at onwrite (node:internal/streams/writable:479:7) at node:internal/fs/streams:416:5 at FSReqCallback.wrapper [as oncomplete] (node:fs:816:5) ``` * if we ignore the error we also do not need the exists check * Update code * Update tests * Update dependencies * Update README * sync package-lock * fix license year information * Release script and GHA update * testing starts Node.js 14
1 parent 872e60d commit ae6ba2d

File tree

14 files changed

+3533
-3264
lines changed

14 files changed

+3533
-3264
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
tags:
7+
# normal versions
8+
- "v?[0-9]+.[0-9]+.[0-9]+"
9+
# pre-releases
10+
- "v?[0-9]+.[0-9]+.[0-9]+-**"
11+
pull_request:
12+
branches: [ master ]
13+
14+
jobs:
15+
build-and-test:
16+
if: contains(github.event.head_commit.message, '[skip ci]') == false
17+
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
matrix:
22+
node-version: [14.x, 16.x, 18.x, 20.x]
23+
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
- name: Use Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
32+
- name: Cache dependencies
33+
if: ${{ !env.ACT }}
34+
uses: actions/cache@v3
35+
with:
36+
path: ./node_modules
37+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
38+
restore-keys: |
39+
${{ runner.os }}-node-
40+
41+
- name: Install dependencies
42+
run: npm ci --ignore-scripts
43+
44+
- name: Install winston@3 peer dependency
45+
run: npm install --no-save winston@3
46+
47+
- run: npm test
48+
49+
# Deploys the final package to NPM
50+
deploy:
51+
needs: [build-and-test]
52+
53+
# Trigger this step only when a commit on master is tagged with a version number
54+
if: |
55+
contains(github.event.head_commit.message, '[skip ci]') == false &&
56+
github.event_name == 'push' &&
57+
startsWith(github.ref, 'refs/tags/')
58+
runs-on: ubuntu-latest
59+
strategy:
60+
matrix:
61+
node-version: [18.x]
62+
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v3
66+
67+
- name: Use Node.js ${{ matrix.node-version }}
68+
uses: actions/setup-node@v4
69+
with:
70+
node-version: ${{ matrix.node-version }}
71+
72+
- name: Extract the version and commit body from the tag
73+
id: extract_release
74+
# The body may be multiline, therefore we need to escape some characters
75+
run: |
76+
VERSION="${{ github.ref }}"
77+
VERSION=${VERSION##*/}
78+
VERSION=${VERSION##*v}
79+
echo "::set-output name=VERSION::$VERSION"
80+
BODY=$(git show -s --format=%b)
81+
BODY="${BODY//'%'/'%25'}"
82+
BODY="${BODY//$'\n'/'%0A'}"
83+
BODY="${BODY//$'\r'/'%0D'}"
84+
echo "::set-output name=BODY::$BODY"
85+
86+
- name: Install Dependencies
87+
run: npm ci --ignore-scripts
88+
89+
# - name: Create a clean build
90+
# run: npm run build
91+
- name: Publish package to npm
92+
run: |
93+
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
94+
npm whoami
95+
npm publish
96+
97+
- name: Create Github Release
98+
uses: actions/create-release@v1
99+
env:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
with:
102+
tag_name: ${{ github.ref }}
103+
release_name: Release v${{ steps.extract_release.outputs.VERSION }}
104+
draft: false
105+
# Prerelease versions create prereleases on Github
106+
prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }}
107+
body: ${{ steps.extract_release.outputs.BODY }}

.github/workflows/unit-tests.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.releaseconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["license"]
3+
}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
<!--
3+
Placeholder for the next version (at the beginning of the line):
4+
## **WORK IN PROGRESS**
5+
-->
6+
## **WORK IN PROGRESS**
7+
* Converted partially to ES6
8+
* Emit "error" event on lwo level filesystem errors to allow logging and handling of them

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 winstonjs
3+
Copyright (c) 2015-2024 winstonjs
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Starting with version 2.0.0, the transport has been refactored to leverage the [
1111
## Compatibility
1212
Please note that if you are using `winston@2`, you will need to use `winston-daily-rotate-file@3`. `winston-daily-rotate-file@4` removed support for `winston@2`.
1313

14+
Starting with version 5.0.0 this module also emits an "error" event for all low level filesystem error cases. Make sure to listen for this event to prevent crashes in your application.
15+
16+
This library should work starting with Node.js 8.x, but tests are only executed for Node.js 14+. Use on your own risk in lower Node.js versions.
17+
1418
## Install
1519
```
1620
npm install winston-daily-rotate-file
@@ -49,8 +53,12 @@ The DailyRotateFile transport can rotate files by minute, hour, day, month, year
4953
maxSize: '20m',
5054
maxFiles: '14d'
5155
});
56+
57+
transport.on('error', error => {
58+
// log or handle errors here
59+
});
5260

53-
transport.on('rotate', function(oldFilename, newFilename) {
61+
transport.on('rotate', (oldFilename, newFilename) => {
5462
// do something fun
5563
});
5664

@@ -85,7 +93,19 @@ using multiple transports
8593
maxFiles: '14d'
8694
});
8795

88-
transport.on('rotate', function(oldFilename, newFilename) {
96+
transport1.on('error', error => {
97+
// log or handle errors here
98+
});
99+
100+
transport2.on('error', error => {
101+
// log or handle errors here
102+
});
103+
104+
transport1.on('rotate', function(oldFilename, newFilename) {
105+
// do something fun
106+
});
107+
108+
transport2.on('rotate', function(oldFilename, newFilename) {
89109
// do something fun
90110
});
91111

@@ -117,7 +137,11 @@ const transport = new winston.transports.DailyRotateFile({
117137
maxFiles: '14d'
118138
});
119139

120-
transport.on('rotate', function(oldFilename, newFilename) {
140+
transport.on('error', error => {
141+
// log or handle errors here
142+
});
143+
144+
transport.on('rotate', (oldFilename, newFilename) => {
121145
// do something fun
122146
});
123147

@@ -134,28 +158,33 @@ logger.info('Hello World!');
134158

135159
``` typescript
136160

137-
import * as winston from 'winston';
138-
import DailyRotateFile from 'winston-daily-rotate-file';
161+
import * as winston from 'winston';
162+
import DailyRotateFile from 'winston-daily-rotate-file';
139163

140164
const transport: DailyRotateFile = new DailyRotateFile({
141165
filename: 'application-%DATE%.log',
142166
datePattern: 'YYYY-MM-DD-HH',
143167
zippedArchive: true,
144168
maxSize: '20m',
145169
maxFiles: '14d'
146-
});
170+
});
171+
172+
transport.on('error', error => {
173+
// log or handle errors here
174+
});
175+
147176

148-
transport.on('rotate', function(oldFilename, newFilename) {
149-
// do something fun
150-
});
177+
transport.on('rotate', (oldFilename, newFilename) => {
178+
// do something fun
179+
});
151180

152181
const logger = winston.createLogger({
153-
transports: [
154-
transport
155-
]});
182+
transports: [
183+
transport
184+
]
185+
});
156186

157187
logger.info('Hello World!');
158-
159188
```
160189

161190

@@ -165,6 +194,7 @@ This transport emits the following custom events:
165194
* **rotate**: fired when the log file is rotated. This event will pass two parameters to the callback (*oldFilename*, *newFilename*).
166195
* **archive**: fired when the log file is archived. This event will pass one parameter to the callback (*zipFilename*).
167196
* **logRemoved**: fired when a log file is removed from the file system. This event will pass one parameter to the callback (*removedFilename*).
197+
* * **error**: fired when a low level filesystem error happens (e.g. EACCESS)
168198

169199
## LICENSE
170200
MIT

0 commit comments

Comments
 (0)