Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare 5.0.0 #389

Merged
merged 10 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Unit Tests

on:
push:
branches: [ master ]
tags:
# normal versions
- "v?[0-9]+.[0-9]+.[0-9]+"
# pre-releases
- "v?[0-9]+.[0-9]+.[0-9]+-**"
pull_request:
branches: [ master ]

jobs:
build-and-test:
if: contains(github.event.head_commit.message, '[skip ci]') == false

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Cache dependencies
if: ${{ !env.ACT }}
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install dependencies
run: npm ci --ignore-scripts

- name: Install winston@3 peer dependency
run: npm install --no-save winston@3

- run: npm test

# Deploys the final package to NPM
deploy:
needs: [build-and-test]

# Trigger this step only when a commit on master is tagged with a version number
if: |
contains(github.event.head_commit.message, '[skip ci]') == false &&
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Extract the version and commit body from the tag
id: extract_release
# The body may be multiline, therefore we need to escape some characters
run: |
VERSION="${{ github.ref }}"
VERSION=${VERSION##*/}
VERSION=${VERSION##*v}
echo "::set-output name=VERSION::$VERSION"
BODY=$(git show -s --format=%b)
BODY="${BODY//'%'/'%25'}"
BODY="${BODY//$'\n'/'%0A'}"
BODY="${BODY//$'\r'/'%0D'}"
echo "::set-output name=BODY::$BODY"

- name: Install Dependencies
run: npm ci --ignore-scripts

# - name: Create a clean build
# run: npm run build
- name: Publish package to npm
run: |
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
npm whoami
npm publish

- name: Create Github Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release v${{ steps.extract_release.outputs.VERSION }}
draft: false
# Prerelease versions create prereleases on Github
prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }}
body: ${{ steps.extract_release.outputs.BODY }}
41 changes: 0 additions & 41 deletions .github/workflows/unit-tests.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .releaseconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["license"]
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog
<!--
Placeholder for the next version (at the beginning of the line):
## **WORK IN PROGRESS**
-->
## **WORK IN PROGRESS**
* Converted partially to ES6
* Emit "error" event on lwo level filesystem errors to allow logging and handling of them
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 winstonjs
Copyright (c) 2015-2024 winstonjs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
56 changes: 43 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Starting with version 2.0.0, the transport has been refactored to leverage the t
## Compatibility
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`.

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.

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.

## Install
```
npm install winston-daily-rotate-file
Expand Down Expand Up @@ -49,8 +53,12 @@ The DailyRotateFile transport can rotate files by minute, hour, day, month, year
maxSize: '20m',
maxFiles: '14d'
});

transport.on('error', error => {
// log or handle errors here
});

transport.on('rotate', function(oldFilename, newFilename) {
transport.on('rotate', (oldFilename, newFilename) => {
// do something fun
});

Expand Down Expand Up @@ -85,7 +93,19 @@ using multiple transports
maxFiles: '14d'
});

transport.on('rotate', function(oldFilename, newFilename) {
transport1.on('error', error => {
// log or handle errors here
});

transport2.on('error', error => {
// log or handle errors here
});

transport1.on('rotate', function(oldFilename, newFilename) {
// do something fun
});

transport2.on('rotate', function(oldFilename, newFilename) {
// do something fun
});

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

transport.on('rotate', function(oldFilename, newFilename) {
transport.on('error', error => {
// log or handle errors here
});

transport.on('rotate', (oldFilename, newFilename) => {
// do something fun
});

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

``` typescript

import * as winston from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';
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('error', error => {
// log or handle errors here
});


transport.on('rotate', function(oldFilename, newFilename) {
// do something fun
});
transport.on('rotate', (oldFilename, newFilename) => {
// do something fun
});

const logger = winston.createLogger({
transports: [
transport
]});
transports: [
transport
]
});

logger.info('Hello World!');

```


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

## LICENSE
MIT
Expand Down
Loading
Loading