Skip to content

Commit 86b88d4

Browse files
committed
feat(3.0): remove fast-json-stringify
1 parent 2f12694 commit 86b88d4

File tree

5 files changed

+36
-61
lines changed

5 files changed

+36
-61
lines changed

README.md

+35-24
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@ A lightweight, flexible logger that merges debug-style namespace management, Win
66
[![Coverage Status][coverage-image]][coverage-url]
77

88
## Table of Contents
9-
- [Features](#features)
10-
- [Installation](#installation)
11-
- [Usage](#usage)
12-
- [Basic logging](#basic-logging)
13-
- [Context ID](#context-id)
14-
- [Namespaces and levels](#namespaces-and-levels)
15-
- [Output formats](#output-formats)
16-
- [JSON format](#json-format)
17-
- [Pretty format](#pretty-format)
18-
- [Custom output functions](#custom-output-functions)
19-
- [Log data and metadata](#log-data-and-metadata)
20-
- [Adding global metadata](#adding-global-metadata)
21-
- [Force logging](#force-logging)
22-
- [Benchmark](#benchmark)
23-
- [Contributing](#contributing)
9+
10+
- [Features](#features)
11+
- [Installation](#installation)
12+
- [Usage](#usage)
13+
- [Basic logging](#basic-logging)
14+
- [Context ID](#context-id)
15+
- [Namespaces and levels](#namespaces-and-levels)
16+
- [Output formats](#output-formats)
17+
- [JSON format](#json-format)
18+
- [Pretty format](#pretty-format)
19+
- [Custom output functions](#custom-output-functions)
20+
- [Log data and metadata](#log-data-and-metadata)
21+
- [Adding global metadata](#adding-global-metadata)
22+
- [Force logging](#force-logging)
23+
- [Benchmark](#benchmark)
24+
- [Contributing](#contributing)
2425

2526
## Features
27+
2628
- **Configurable log levels**: Set log levels globally or per namespace for detailed control.
2729
- **Flexible output formats**: Supports JSON, Pretty-print, and custom output adapters.
2830
- **Context ID support**: Optionally track logs across function calls by assigning a unique context ID.
@@ -33,6 +35,7 @@ A lightweight, flexible logger that merges debug-style namespace management, Win
3335
## Installation
3436

3537
Install via npm, yarn or pnpm:
38+
3639
```sh
3740
npm add @ekino/logger
3841
yarn add @ekino/logger
@@ -41,17 +44,18 @@ pnpm add @ekino/logger
4144

4245
## Usage
4346

44-
By default, `@ekino/logger` outputs `warn` and `error` levels for all namespaces, with logs written to stdout in JSON format.
47+
By default, `@ekino/logger` outputs `warn` and `error` levels for all namespaces, with logs written to stdout in JSON format.
4548

4649
Adjust the log level globally or per namespace using the `LOG_LEVEL` environment variable or programmatically with `setLevel` and `setNamespaces`.
4750

4851
### Basic logging
4952

50-
`@ekino/logger` provides five log levels: `trace`, `debug`, `info`, `warn`, and `error`. Setting a specific level enables it and all higher-priority levels.
53+
`@ekino/logger` provides five log levels: `trace`, `debug`, `info`, `warn`, and `error`. Setting a specific level enables it and all higher-priority levels.
5154

5255
By default, setting info will enable `info`, `warn`, and `error`, but not debug or trace. The log levels are defined as:
5356

5457
Log level priorities:
58+
5559
```js
5660
{ trace: 0, debug: 1, info: 2, warn: 3, error: 4 }
5761
```
@@ -91,6 +95,7 @@ Output example:
9195
Namespaces offer flexibility for selectively enabling logs. Set a default global log level and configure specific namespaces with unique levels, including `none` to disable.
9296

9397
To configure namespaces:
98+
9499
```js
95100
const { setLevel, setNamespaces } = require('@ekino/logger')
96101

@@ -182,23 +187,28 @@ Output example:
182187
![Example](docs/images/example_context.png)
183188

184189
### Force logging
190+
185191
Override the log level for critical messages by forcing them to be logged:
192+
186193
```js
187-
logger.debug('Will be logged regardless of level', { forceLogging: true });
194+
logger.debug('Will be logged regardless of level', { forceLogging: true })
188195
```
189196

190197
## Benchmark
191-
Below is a performance comparison of several popular Node.js logging libraries, including @ekino/logger. Benchmarks were conducted using Node.js v22.10.0, with results measured in operations per second (higher values indicate better performance).
198+
199+
Below is a performance comparison of several popular Node.js logging libraries, including @ekino/logger. Benchmarks were conducted using Node.js v23.13.0, with results measured in operations per second (higher values indicate better performance).
200+
192201
```bash
193202
┌─────────┬──────────────────────┬───────────┐
194203
│ (index) │ library │ ops/sec │
195204
├─────────┼──────────────────────┼───────────┤
196-
│ 0 │ 'Pino' '124,828'
197-
│ 1 │ '@ekino/logger v3.x' '118,385'
198-
│ 2 │ '@ekino/logger v2.x''104,004'
199-
│ 3 │ 'Winston''67,536'
205+
│ 0 │ '@ekino/logger v3.x' '129,082'
206+
│ 1 │ 'Pino' '112,727'
207+
│ 2 │ '@ekino/logger v2.x''112,423'
208+
│ 3 │ 'Winston''55,411'
200209
└─────────┴──────────────────────┴───────────┘
201210
```
211+
202212
**Note**: Benchmark results may vary depending on environment and configuration. This table provides a general reference for relative performance between libraries.
203213

204214
For more detailed benchmark results, please refer to the [benchmarks](./benchmarks/) folder.
@@ -210,4 +220,5 @@ Contributions are welcome! Please refer to our [CONTRIBUTING.md](CONTRIBUTING.md
210220
[npm-image]: https://img.shields.io/npm/v/@ekino/logger.svg?style=flat-square
211221
[npm-url]: https://www.npmjs.com/package/@ekino/logger
212222
[coverage-image]: https://img.shields.io/coveralls/ekino/node-logger/master.svg?style=flat-square
213-
[coverage-url]: https://coveralls.io/github/ekino/node-logger?branch=master
223+
[coverage-url]: https://coveralls.io/github/ekino/node-logger?branch=master
224+

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"node": ">=18"
4646
},
4747
"dependencies": {
48-
"fast-json-stringify": "6.x",
4948
"prettyoutput": "1.x"
5049
},
5150
"devDependencies": {

src/json_schema.ts

-26
This file was deleted.

src/output_utils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { ReplacerFunction } from './definitions.js'
2-
import { fastStringifyLog } from './json_schema.js'
32

43
/**
54
* Replace circular reference when used with JSON.stringify
@@ -24,7 +23,7 @@ export const getCircularReplacer = (): ReplacerFunction => {
2423
*/
2524
export const stringifyLog = (log: Record<string, unknown>): string => {
2625
try {
27-
return fastStringifyLog(log)
26+
return JSON.stringify(log)
2827
} catch (e) {
2928
return JSON.stringify(log, getCircularReplacer())
3029
}

test/output_utils.test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { describe, expect, it, vi } from 'vitest'
2-
import * as jsonSchema from '../src/json_schema.js'
32
import * as outputUtils from '../src/output_utils.js'
43

54
describe('outputUtils', () => {
@@ -29,16 +28,9 @@ describe('outputUtils', () => {
2928

3029
it('should fallback to standard stringify when fastStringifyLog fails', () => {
3130
const obj = { test: 'value' }
32-
const fastStringifyLogMock = vi
33-
.spyOn(jsonSchema, 'fastStringifyLog')
34-
.mockImplementation(() => {
35-
throw new Error('Mocked error')
36-
})
3731

3832
const result = outputUtils.stringifyLog(obj)
3933
expect(result).toBe('{"test":"value"}')
40-
41-
fastStringifyLogMock.mockRestore()
4234
})
4335
})
4436

0 commit comments

Comments
 (0)