Skip to content

Conversation

@tduyng
Copy link
Contributor

@tduyng tduyng commented Feb 24, 2025

Summary

Rewrite @ekino/logger for v3.0

Motivation

  • It's been so long time the library is not matained
  • Rewrite this library for adapting the modern Node.js (Typescript, ESM)

What has changed?

Here are the key changes made in this PR:

  • Rewritten in ESM
  • Support for dual package (CommonJS and ESM)
  • Rewritten in TypeScript
  • Removed many unnecessary dependencies
  • Replaced yarn with pnpm, which is faster and more convenient with different commands and management
  • Upgraded GitHub Actions, rewrote some deprecated syntax
  • Using git-cliff on GitHub Actions for easily customizable CHANGELOG
  • Replaced ESLint + Prettier with Biome, which is faster, has sufficient rules, and is easier to set up
  • Rewrote all tests from ava + sinon.js + nyc + ts-node to vitest (compatible with ESM)
  • Create a benchmark compare with pino.js and winston
  • Refactored and cleaned up code, focusing on performance, and much more...

Test plan

  • All unit tests have been correctly rewritten with Vitest
  • All functional test behaviors are ensured

tduyng added 30 commits October 21, 2024 16:00
@tduyng
Copy link
Contributor Author

tduyng commented May 23, 2025

TODO: fix github-action for release and changelog.


## How to Contribute

Follow this guide to ensure a smooth contribution process. If you're planning significant work or substantial changes, please create an issue labeled "contribution enquiry" to discuss your proposal. This will help ensure that your work aligns with the project's goals.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The label does not exist
  2. A new contributor cannot add labels, most of the time a member must set the labels for him

2. **Clone Your Fork**
Clone your forked repo to your local machine:
```bash
git clone git@github.com:ekino/node-logger.git

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
git clone git@github.com:ekino/node-logger.git
git clone git@github.com:[YOUR_GITHUB_ACCOUNT]/node-logger.git

since you forked the repository the address is not correct

Ensure your changes are reliable by including tests. For small patches, a simple test is fine; for new features, create a dedicated test suite.

7. **Coding Style and Conventions**
Maintain the project’s coding standards. Consistent indentation, comments, and style improve readability.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could invite the contributor to install official biome ext for vscode ? (or any other IDE)
https://biomejs.dev/reference/vscode/


- Benchmark basic
```bash
node ./benchmarks/basic.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node ./benchmarks/basic.js
pnpm run build
node ./benchmarks/basic.js

- Benchmark with complex object

```bash
node ./benchmarks/complex.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node ./benchmarks/complex.js
pnpm run build
node ./benchmarks/complex.js

Comment on lines +26 to +36
Tested on Nodejs 22.10.0
```bash
┌─────────┬──────────────────────┬──────────┐
│ (index) │ library │ ops/sec │
├─────────┼──────────────────────┼──────────┤
│ 0 │ 'Pino''26,506'
│ 1 │ '@ekino/logger v3.x''21,915'
│ 2 │ '@ekino/logger v2.x''18,826'
│ 3 │ 'Winston''4,251'
└─────────┴──────────────────────┴──────────┘
``` No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Tested on Nodejs 22.10.0
```bash
┌─────────┬──────────────────────┬──────────┐
│ (index) │ library │ ops/sec │
├─────────┼──────────────────────┼──────────┤
│ 0 │ 'Pino' │ '26,506' │
1 │ '@ekino/logger v3.x' │ '21,915' │
2 │ '@ekino/logger v2.x' │ '18,826' │
3 │ 'Winston' │ '4,251'
└─────────┴──────────────────────┴──────────┘
```
Tested on Nodejs 24.3.0
Macbook Pro AppleM2 Pro (macos 15.7.2)
```bash
┌─────────┬──────────────────────┬──────────┐
│ (index) │ library │ ops/sec │
├─────────┼──────────────────────┼──────────┤
0 │ 'Pino' │ '42,089' │
1 │ '@ekino/logger v3.x' │ '31,158' │
2 │ '@ekino/logger v2.x' │ '26,871'
│ 3 │ 'Winston' │ '2,743' │
└─────────┴──────────────────────┴──────────┘


- **Dual ESM and CommonJS**: Added support for both module formats. No syntax changes needed from 2.x.
- **Functional style**: Refactored to use a fully functional API, removing internal objects. Update code that accessed internals directly.
- **Node.js update**: Dropped support for Node 14 and 16. Now compatible with Node 18, 20, 22, and above.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **Node.js update**: Dropped support for Node 14 and 16. Now compatible with Node 18, 20, 22, and above.
- **Node.js update**: Dropped support for Node 16, and 18. Now compatible with Node 20, 22, 24, and above.


logger.setNamespaces('namespace:*')
logger.setLevel('debug')
//logger.setOutput(logger.outputs.json)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//logger.setOutput(logger.outputs.json)


logger.setNamespaces('namespace:*')
logger.setLevel('debug')
//logger.setOutput(logger.outputs.json)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//logger.setOutput(logger.outputs.json)


logger.setNamespaces('namespace:*')
logger.setLevel('debug')
//logger.setOutput(logger.outputs.json)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//logger.setOutput(logger.outputs.json)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants