@andrew_l/pino-pretty 0.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/index.cjs +596 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +181 -0
- package/dist/index.d.mts +181 -0
- package/dist/index.d.ts +181 -0
- package/dist/index.mjs +571 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Andrew L. <andrew.io.dev@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Pino Pretty
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
A highly customizable [pino](https://www.npmjs.com/package/pino) transport that transforms JSON logs into beautiful, readable output with colors, icons, and intelligent formatting for development.
|
|
7
|
+
|
|
8
|
+
Inspired by [consola](https://www.npmjs.com/package/consola)
|
|
9
|
+
|
|
10
|
+
[Documentation](https://men232.github.io/toolkit/reference/@andrew_l/pino-pretty/)
|
|
11
|
+
|
|
12
|
+
<img src="https://github.com/user-attachments/assets/26d13b82-6d07-456f-b204-a6455df2dd3e" />
|
|
13
|
+
|
|
14
|
+
<!-- install placeholder -->
|
|
15
|
+
|
|
16
|
+
## 📋 Features
|
|
17
|
+
|
|
18
|
+
- **Highly Customizable:** Configure colors, icons, badges, and formatting options for each log level
|
|
19
|
+
- **Intelligent Formatting:** Smart object inspection with configurable depth and string truncation
|
|
20
|
+
- **Type-Aware Coloring:** Different colors for strings, numbers, booleans, errors, and other data types
|
|
21
|
+
- **Terminal Optimized:** Respects terminal width and supports both colored and plain text output
|
|
22
|
+
|
|
23
|
+
## ⚠️ Cautions
|
|
24
|
+
|
|
25
|
+
To ensure optimal performance and display, please keep the following in mind:
|
|
26
|
+
|
|
27
|
+
- **Terminal Width:** Set `columns` to `process.stdout.columns` for proper formatting
|
|
28
|
+
- **Color Support:** Disable `colorize` when piping to files or in CI environments without color support
|
|
29
|
+
- **Memory Usage:** Be mindful of `depth` and `maxStringLength` settings for large objects
|
|
30
|
+
- **Performance:** Do not use in production logs output.
|
|
31
|
+
|
|
32
|
+
## 🚀 Example: Basic Usage
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
import pino from 'pino';
|
|
36
|
+
|
|
37
|
+
const logger = pino({
|
|
38
|
+
serializers: {
|
|
39
|
+
// To enable pretty error stack trace displaying.
|
|
40
|
+
error: pino.stdSerializers.errWithCause,
|
|
41
|
+
err: pino.stdSerializers.errWithCause,
|
|
42
|
+
},
|
|
43
|
+
transport: {
|
|
44
|
+
target: '@andrew_l/pino-pretty',
|
|
45
|
+
options: {
|
|
46
|
+
columns: process.stdout.columns,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
logger.info('Basic pino-pretty setup successful');
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 🚀 Example: Advanced Configuration
|
|
55
|
+
|
|
56
|
+
Customize every aspect of your log formatting:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import pino from 'pino';
|
|
60
|
+
import type { PinoPretty } from '@andrew_l/pino-pretty';
|
|
61
|
+
|
|
62
|
+
const logger = pino({
|
|
63
|
+
transport: {
|
|
64
|
+
target: '@andrew_l/pino-pretty',
|
|
65
|
+
options: {
|
|
66
|
+
columns: process.stdout.columns,
|
|
67
|
+
colorize: !process.env.CI,
|
|
68
|
+
indent: 4,
|
|
69
|
+
depth: 3,
|
|
70
|
+
maxStringLength: 200,
|
|
71
|
+
numericSeparator: true,
|
|
72
|
+
quoteStyle: 'double',
|
|
73
|
+
ignore: 'hostname,pid',
|
|
74
|
+
|
|
75
|
+
// Custom level configurations
|
|
76
|
+
levels: {
|
|
77
|
+
10: { icon: '🔍', color: ['gray', 'dim'], badge: 'TRACE' },
|
|
78
|
+
20: { icon: '📋', color: 'cyan', badge: 'INFO' },
|
|
79
|
+
30: { icon: '⚠️', color: ['yellow', 'bold'], badge: 'WARN' },
|
|
80
|
+
40: { icon: '❌', color: ['red', 'bold'], badge: 'ERROR' },
|
|
81
|
+
50: { icon: '💀', color: ['magenta', 'bold'], badge: 'FATAL' },
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
// Custom type coloring
|
|
85
|
+
types: {
|
|
86
|
+
string: { color: 'green' },
|
|
87
|
+
number: { color: 'cyan' },
|
|
88
|
+
boolean: { color: 'yellow' },
|
|
89
|
+
object: { color: 'blue' },
|
|
90
|
+
error: { color: ['gray'] },
|
|
91
|
+
errorStack: { color: 'cyan' },
|
|
92
|
+
time: { color: 'gray' },
|
|
93
|
+
name: { color: ['blue', 'bold'] },
|
|
94
|
+
},
|
|
95
|
+
} as PinoPretty.Options,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
logger.info('Custom pino-pretty setup successful');
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 🤔 Why Use This Package?
|
|
103
|
+
|
|
104
|
+
1. **Enhanced Readability:** Transform cryptic JSON logs into human-readable, visually appealing output
|
|
105
|
+
2. **Development Productivity:** Quickly identify issues with color-coded levels and intelligent formatting
|
|
106
|
+
3. **Highly Customizable:** Every aspect of formatting can be tailored to your preferences
|