@nestjs-labs/pino-http-extra 0.0.1 → 1.2.0
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/README.md +193 -94
- package/package.json +1 -1
- package/dist/formatters.js +0 -22
- package/dist/formatters.js.map +0 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/options.js +0 -54
- package/dist/options.js.map +0 -1
- package/dist/serializers.d.ts +0 -3
- package/dist/serializers.d.ts.map +0 -1
- package/dist/serializers.js +0 -26
- package/dist/serializers.js.map +0 -1
- package/dist/streams.d.ts +0 -6
- package/dist/streams.d.ts.map +0 -1
- package/dist/streams.js +0 -52
- package/dist/streams.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,147 +2,246 @@
|
|
|
2
2
|
|
|
3
3
|
Enhanced pino-http with OpenTelemetry, Loki, file rotation and enterprise features.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@nestjs-labs/pino-http-extra)
|
|
6
|
+
[](https://github.com/nestjs-labs/nestjs-pino-extra/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
## 🚀 Features
|
|
9
|
+
|
|
10
|
+
- 🔍 **OpenTelemetry Integration**: Automatic span and trace ID injection for distributed tracing
|
|
11
|
+
- 📊 **Loki Transport**: Send logs to Grafana Loki for centralized log management
|
|
12
|
+
- 📁 **File Rotation**: Automatic log file rotation with compression (1GB size, daily rotation)
|
|
13
|
+
- 🎨 **Pretty Logging**: Colored and formatted console output for development
|
|
14
|
+
- 🔒 **Security**: Automatic redaction of sensitive fields (password, user data)
|
|
15
|
+
- ⚡ **Performance**: High-performance logging with Pino
|
|
16
|
+
- 🆔 **Request ID**: Automatic request ID generation and tracking
|
|
17
|
+
- 📈 **Response Time**: Automatic response time tracking
|
|
18
|
+
- 🎯 **Smart Log Levels**: Status code-based log level determination
|
|
19
|
+
|
|
20
|
+
## 📦 Installation
|
|
6
21
|
|
|
7
22
|
```bash
|
|
8
23
|
npm install @nestjs-labs/pino-http-extra
|
|
9
24
|
```
|
|
10
25
|
|
|
11
|
-
##
|
|
26
|
+
## 🏃♂️ Quick Start
|
|
12
27
|
|
|
13
|
-
|
|
14
|
-
- 📊 **Loki Transport**: Send logs to Grafana Loki
|
|
15
|
-
- 📁 **File Rotation**: Automatic log file rotation with compression
|
|
16
|
-
- 🎨 **Pretty Logging**: Colored and formatted console output
|
|
17
|
-
- 🔒 **Security**: Automatic redaction of sensitive fields
|
|
18
|
-
- ⚡ **Performance**: High-performance logging with Pino
|
|
28
|
+
### Basic Setup
|
|
19
29
|
|
|
20
|
-
|
|
30
|
+
```typescript
|
|
31
|
+
import pino from 'pino'
|
|
32
|
+
import pinoHttp from 'pino-http'
|
|
33
|
+
import { getPinoHttpOption, getMultiDestinationStream } from '@nestjs-labs/pino-http-extra'
|
|
34
|
+
import "dotenv/config"
|
|
35
|
+
|
|
36
|
+
const level = process.env.LOG_LEVEL || 'info'
|
|
37
|
+
const app = process.env.APP_NAME || 'my-app'
|
|
38
|
+
const pinoHttpOption = getPinoHttpOption(level, 'spanId', 'traceId')
|
|
39
|
+
const filename = process.env.LOG_FILE || 'logs/app.log'
|
|
40
|
+
const loki = process.env.LOKI_HOST
|
|
41
|
+
const multiStream = getMultiDestinationStream(app, level as pino.Level, filename, loki)
|
|
42
|
+
const pinoHttpLogger = pinoHttp(pinoHttpOption)
|
|
43
|
+
const logger = pino(pinoHttpOption, multiStream)
|
|
44
|
+
```
|
|
21
45
|
|
|
22
|
-
###
|
|
46
|
+
### Express.js Integration
|
|
23
47
|
|
|
24
48
|
```typescript
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
import express from 'express'
|
|
50
|
+
import pinoHttp from 'pino-http'
|
|
51
|
+
import { getPinoHttpOption, getMultiDestinationStream } from '@nestjs-labs/pino-http-extra'
|
|
52
|
+
|
|
53
|
+
const app = express()
|
|
54
|
+
const multiStream = getMultiDestinationStream(app, 'info', 'logs/app.log', 'http://loki:3100')
|
|
55
|
+
const pinoHttpOption = getPinoHttpOption()
|
|
56
|
+
const pinoHttpLogger = pinoHttp(pinoHttpOption)
|
|
57
|
+
const logger = pino(pinoHttpOption, multiStream)
|
|
58
|
+
|
|
59
|
+
// Use as middleware
|
|
60
|
+
app.use(pinoHttpLogger)
|
|
61
|
+
|
|
62
|
+
app.get('/', (req, res) => {
|
|
63
|
+
req.log.info('Hello from pino-http-extra!')
|
|
64
|
+
res.json({ message: 'Hello World!' })
|
|
39
65
|
})
|
|
40
|
-
export class AppModule {}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Environment Variables
|
|
44
66
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# Optional
|
|
50
|
-
LOG_LEVEL=info
|
|
51
|
-
LOG_FILE=/var/log/app.log
|
|
52
|
-
LOG_LOKI=http://loki:3100
|
|
53
|
-
OTEL_SPAN_ID_KEY=spanId
|
|
54
|
-
OTEL_TRACE_ID_KEY=traceId
|
|
67
|
+
app.listen(3000, () => {
|
|
68
|
+
logger.info('Server running on port 3000')
|
|
69
|
+
})
|
|
55
70
|
```
|
|
56
71
|
|
|
57
|
-
###
|
|
72
|
+
### Fastify Integration
|
|
58
73
|
|
|
59
74
|
```typescript
|
|
60
|
-
import
|
|
61
|
-
import {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
imports: [
|
|
66
|
-
ConfigModule.forRoot(),
|
|
67
|
-
LoggerModule.forRootAsync({
|
|
68
|
-
imports: [ConfigModule],
|
|
69
|
-
useFactory: (configService: ConfigService) =>
|
|
70
|
-
getNestjsPinoModuleOptions(configService, {
|
|
71
|
-
exclude: [
|
|
72
|
-
{ method: 0, path: '/health' },
|
|
73
|
-
{ method: 0, path: '/metrics' },
|
|
74
|
-
],
|
|
75
|
-
}),
|
|
76
|
-
inject: [ConfigService],
|
|
77
|
-
}),
|
|
78
|
-
],
|
|
75
|
+
import Fastify from 'fastify'
|
|
76
|
+
import { getPinoHttpOption, getMultiDestinationStream } from '@nestjs-labs/pino-http-extra'
|
|
77
|
+
|
|
78
|
+
const fastify = Fastify({
|
|
79
|
+
logger: getPinoHttpOption()
|
|
79
80
|
})
|
|
80
|
-
export class AppModule {}
|
|
81
|
-
```
|
|
82
81
|
|
|
83
|
-
|
|
82
|
+
fastify.get('/', async (request, reply) => {
|
|
83
|
+
request.log.info('Hello from pino-http-extra!')
|
|
84
|
+
return { message: 'Hello World!' }
|
|
85
|
+
})
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
fastify.listen({ port: 3000 })
|
|
88
|
+
```
|
|
86
89
|
|
|
87
|
-
|
|
90
|
+
### Advanced Configuration
|
|
88
91
|
|
|
89
|
-
|
|
92
|
+
```typescript
|
|
93
|
+
import { getPinoHttpOption, getMultiDestinationStream } from '@nestjs-labs/pino-http-extra'
|
|
94
|
+
|
|
95
|
+
// Custom OpenTelemetry keys
|
|
96
|
+
const options = getPinoHttpOption('debug', 'customSpanId', 'customTraceId')
|
|
97
|
+
|
|
98
|
+
// Multi-destination with custom settings
|
|
99
|
+
const multiStream = getMultiDestinationStream(
|
|
100
|
+
'my-app', // app name
|
|
101
|
+
'info', // log level
|
|
102
|
+
'/var/log/app.log', // file path (optional)
|
|
103
|
+
'http://loki:3100' // loki host (optional)
|
|
104
|
+
)
|
|
105
|
+
```
|
|
90
106
|
|
|
91
|
-
|
|
92
|
-
- `configService`: ConfigService - NestJS configuration service
|
|
93
|
-
- `overrides`: Params (optional) - Overrides for the module options
|
|
107
|
+
## 📚 API Reference
|
|
94
108
|
|
|
95
|
-
|
|
109
|
+
### Core Functions
|
|
96
110
|
|
|
97
111
|
#### `getPinoHttpOption(level?, spanIdKey?, traceIdKey?)`
|
|
98
112
|
|
|
99
|
-
Get pino-http options with OpenTelemetry integration.
|
|
113
|
+
Get pino-http options with OpenTelemetry integration and security features.
|
|
100
114
|
|
|
101
115
|
**Parameters:**
|
|
102
|
-
- `level`: string (default: 'info') - Log level
|
|
103
|
-
- `spanIdKey`: string (default: 'spanId') - OpenTelemetry span ID key
|
|
104
|
-
- `traceIdKey`: string (default: 'traceId') - OpenTelemetry trace ID key
|
|
116
|
+
- `level`: `string` (default: `'info'`) - Log level
|
|
117
|
+
- `spanIdKey`: `string` (default: `'spanId'`) - OpenTelemetry span ID key
|
|
118
|
+
- `traceIdKey`: `string` (default: `'traceId'`) - OpenTelemetry trace ID key
|
|
105
119
|
|
|
106
|
-
**Returns:** Options - Configured pino-http options
|
|
120
|
+
**Returns:** `Options` - Configured pino-http options
|
|
121
|
+
|
|
122
|
+
**Features:**
|
|
123
|
+
- Automatic request ID generation
|
|
124
|
+
- Response time tracking
|
|
125
|
+
- Status code-based log levels
|
|
126
|
+
- Sensitive data redaction
|
|
127
|
+
- OpenTelemetry integration
|
|
107
128
|
|
|
108
129
|
#### `getMultiDestinationStream(app, level?, filepath?, loki?)`
|
|
109
130
|
|
|
110
131
|
Create multi-destination stream supporting pretty, file, and Loki outputs.
|
|
111
132
|
|
|
112
133
|
**Parameters:**
|
|
113
|
-
- `app`: string - Application name
|
|
114
|
-
- `level`: pino.Level (default: 'info') - Log level
|
|
115
|
-
- `filepath`: string (optional) - Log file path for rotation
|
|
116
|
-
- `loki`: string (optional) - Loki host URL
|
|
134
|
+
- `app`: `string` - Application name for Loki labels
|
|
135
|
+
- `level`: `pino.Level` (default: `'info'`) - Log level
|
|
136
|
+
- `filepath`: `string` (optional) - Log file path for rotation
|
|
137
|
+
- `loki`: `string` (optional) - Loki host URL
|
|
138
|
+
|
|
139
|
+
**Returns:** `MultiStreamRes` - Configured multi-stream
|
|
140
|
+
|
|
141
|
+
**Features:**
|
|
142
|
+
- Pretty console output with colors
|
|
143
|
+
- File rotation (1GB size, daily rotation, gzip compression)
|
|
144
|
+
- Loki transport with batching
|
|
117
145
|
|
|
118
|
-
|
|
146
|
+
### Stream Functions
|
|
119
147
|
|
|
120
|
-
|
|
148
|
+
#### `createPrettyStreamEntry(app, level)`
|
|
149
|
+
|
|
150
|
+
Create pretty console stream entry.
|
|
151
|
+
|
|
152
|
+
#### `createFileStreamEntry(app, level, filepath)`
|
|
153
|
+
|
|
154
|
+
Create file rotation stream entry.
|
|
155
|
+
|
|
156
|
+
#### `createLokiStreamEntry(app, level, host)`
|
|
157
|
+
|
|
158
|
+
Create Loki transport stream entry.
|
|
159
|
+
|
|
160
|
+
### Formatters
|
|
161
|
+
|
|
162
|
+
#### `getOtelFormatters(spanIdKey?, traceIdKey?)`
|
|
163
|
+
|
|
164
|
+
Get OpenTelemetry formatters for automatic span and trace ID injection.
|
|
165
|
+
|
|
166
|
+
### Serializers
|
|
167
|
+
|
|
168
|
+
#### `getSerializers()`
|
|
169
|
+
|
|
170
|
+
Get enhanced serializers for request/response objects.
|
|
171
|
+
|
|
172
|
+
## 🔧 Examples
|
|
121
173
|
|
|
122
174
|
### Custom Logging
|
|
123
175
|
|
|
124
176
|
```typescript
|
|
125
|
-
import
|
|
177
|
+
import pino from 'pino'
|
|
178
|
+
import { getPinoHttpOption } from '@nestjs-labs/pino-http-extra'
|
|
126
179
|
|
|
127
|
-
|
|
128
|
-
export class AppService {
|
|
129
|
-
private readonly logger = new Logger(AppService.name);
|
|
180
|
+
const logger = pino(getPinoHttpOption())
|
|
130
181
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
}
|
|
182
|
+
logger.info('Application started')
|
|
183
|
+
logger.warn('Warning message')
|
|
184
|
+
logger.error('Error occurred', { error: new Error('Something went wrong') })
|
|
136
185
|
```
|
|
137
186
|
|
|
138
187
|
### HTTP Request Logging
|
|
139
188
|
|
|
140
189
|
The middleware automatically logs HTTP requests with:
|
|
141
|
-
- Request ID generation
|
|
142
|
-
- Response time tracking
|
|
143
|
-
- Status code-based log levels
|
|
144
|
-
- Sensitive data redaction
|
|
145
190
|
|
|
146
|
-
|
|
191
|
+
- **Request ID**: Automatically generated and tracked
|
|
192
|
+
- **Response Time**: Automatic timing of request duration
|
|
193
|
+
- **Status Code Logging**:
|
|
194
|
+
- 2xx: `info` level
|
|
195
|
+
- 4xx: `warn` level
|
|
196
|
+
- 5xx: `error` level
|
|
197
|
+
- 3xx: `silent` level
|
|
198
|
+
- **Sensitive Data Redaction**: Automatic redaction of password fields
|
|
199
|
+
- **OpenTelemetry Integration**: Automatic span and trace ID injection
|
|
200
|
+
|
|
201
|
+
### Log Output Example
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"level": "info",
|
|
206
|
+
"time": "2024-01-15T10:30:00.000Z",
|
|
207
|
+
"reqId": "550e8400-e29b-41d4-a716-446655440000",
|
|
208
|
+
"spanId": "1234567890abcdef",
|
|
209
|
+
"traceId": "abcdef1234567890",
|
|
210
|
+
"req": {
|
|
211
|
+
"method": "GET",
|
|
212
|
+
"url": "/api/users",
|
|
213
|
+
"headers": {
|
|
214
|
+
"user-agent": "Mozilla/5.0..."
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
"res": {
|
|
218
|
+
"statusCode": 200
|
|
219
|
+
},
|
|
220
|
+
"responseTime": 45,
|
|
221
|
+
"msg": "request completed"
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## 🔒 Security Features
|
|
226
|
+
|
|
227
|
+
- **Automatic Redaction**: Sensitive fields are automatically redacted
|
|
228
|
+
- **Request ID Tracking**: Each request gets a unique ID for tracing
|
|
229
|
+
- **No Sensitive Data**: Passwords and user credentials are never logged
|
|
230
|
+
|
|
231
|
+
## 🚀 Performance
|
|
232
|
+
|
|
233
|
+
- **High Performance**: Built on Pino, one of the fastest Node.js loggers
|
|
234
|
+
- **Minimal Overhead**: Optimized for production use
|
|
235
|
+
- **Async Logging**: Non-blocking log operations
|
|
236
|
+
- **Batching**: Loki transport supports batching for better performance
|
|
237
|
+
|
|
238
|
+
## 📄 License
|
|
239
|
+
|
|
240
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
241
|
+
|
|
242
|
+
## 🔗 Links
|
|
147
243
|
|
|
148
|
-
|
|
244
|
+
- [Documentation](https://nestjs-labs.github.io/nestjs-pino-extra)
|
|
245
|
+
- [GitHub Repository](https://github.com/nestjs-labs/nestjs-pino-extra)
|
|
246
|
+
- [NPM Package](https://www.npmjs.com/package/@nestjs-labs/pino-http-extra)
|
|
247
|
+
- [Issues](https://github.com/nestjs-labs/nestjs-pino-extra/issues)
|
package/package.json
CHANGED
package/dist/formatters.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOtelFormatters = getOtelFormatters;
|
|
4
|
-
const api_1 = require("@opentelemetry/api");
|
|
5
|
-
function getOtelFormatters(spanIdKey = 'spanId', traceIdKey = 'traceId') {
|
|
6
|
-
return {
|
|
7
|
-
level: (label) => {
|
|
8
|
-
return { level: label };
|
|
9
|
-
},
|
|
10
|
-
log(object) {
|
|
11
|
-
const span = api_1.trace.getSpan(api_1.context.active());
|
|
12
|
-
if (!span)
|
|
13
|
-
return object;
|
|
14
|
-
const spanContext = api_1.trace.getSpan(api_1.context.active())?.spanContext();
|
|
15
|
-
if (!spanContext)
|
|
16
|
-
return object;
|
|
17
|
-
const { spanId, traceId } = spanContext;
|
|
18
|
-
return { ...object, [spanIdKey]: spanId, [traceIdKey]: traceId };
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=formatters.js.map
|
package/dist/formatters.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":";;AAMA,8CAsBC;AA5BD,4CAAoD;AAMpD,SAAgB,iBAAiB,CAChC,SAAS,GAAG,QAAQ,EACpB,UAAU,GAAG,SAAS;IAEtB,OAAO;QACN,KAAK,EAAE,CAAC,KAAa,EAAE,EAAE;YACxB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QACzB,CAAC;QAED,GAAG,CAAC,MAA+B;YAClC,MAAM,IAAI,GAAG,WAAK,CAAC,OAAO,CAAC,aAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YAE7C,IAAI,CAAC,IAAI;gBAAE,OAAO,MAAM,CAAC;YACzB,MAAM,WAAW,GAAG,WAAK,CAAC,OAAO,CAAC,aAAO,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC;YAEnE,IAAI,CAAC,WAAW;gBAAE,OAAO,MAAM,CAAC;YAEhC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAC;YAExC,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC;QAClE,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMultiDestinationStream = exports.createPrettyStreamEntry = exports.createLokiStreamEntry = exports.createFileStreamEntry = exports.getSerializers = exports.getPinoHttpOption = exports.getOtelFormatters = void 0;
|
|
4
|
-
var formatters_js_1 = require("./formatters.js");
|
|
5
|
-
Object.defineProperty(exports, "getOtelFormatters", { enumerable: true, get: function () { return formatters_js_1.getOtelFormatters; } });
|
|
6
|
-
var options_js_1 = require("./options.js");
|
|
7
|
-
Object.defineProperty(exports, "getPinoHttpOption", { enumerable: true, get: function () { return options_js_1.getPinoHttpOption; } });
|
|
8
|
-
var serializers_js_1 = require("./serializers.js");
|
|
9
|
-
Object.defineProperty(exports, "getSerializers", { enumerable: true, get: function () { return serializers_js_1.getSerializers; } });
|
|
10
|
-
var streams_js_1 = require("./streams.js");
|
|
11
|
-
Object.defineProperty(exports, "createFileStreamEntry", { enumerable: true, get: function () { return streams_js_1.createFileStreamEntry; } });
|
|
12
|
-
Object.defineProperty(exports, "createLokiStreamEntry", { enumerable: true, get: function () { return streams_js_1.createLokiStreamEntry; } });
|
|
13
|
-
Object.defineProperty(exports, "createPrettyStreamEntry", { enumerable: true, get: function () { return streams_js_1.createPrettyStreamEntry; } });
|
|
14
|
-
Object.defineProperty(exports, "getMultiDestinationStream", { enumerable: true, get: function () { return streams_js_1.getMultiDestinationStream; } });
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAOA,iDAAoD;AAA3C,kHAAA,iBAAiB,OAAA;AAC1B,2CAAiD;AAAxC,+GAAA,iBAAiB,OAAA;AAC1B,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,2CAKsB;AAJpB,mHAAA,qBAAqB,OAAA;AACrB,mHAAA,qBAAqB,OAAA;AACrB,qHAAA,uBAAuB,OAAA;AACvB,uHAAA,yBAAyB,OAAA"}
|
package/dist/options.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPinoHttpOption = getPinoHttpOption;
|
|
7
|
-
const node_crypto_1 = require("node:crypto");
|
|
8
|
-
const pino_1 = __importDefault(require("pino"));
|
|
9
|
-
const formatters_js_1 = require("./formatters.js");
|
|
10
|
-
const serializers_js_1 = require("./serializers.js");
|
|
11
|
-
function getPinoHttpOption(level = 'info', spanIdKey = 'spanId', traceIdKey = 'traceId') {
|
|
12
|
-
return {
|
|
13
|
-
level,
|
|
14
|
-
quietReqLogger: false,
|
|
15
|
-
timestamp: pino_1.default.stdTimeFunctions.isoTime,
|
|
16
|
-
customAttributeKeys: {
|
|
17
|
-
req: 'req',
|
|
18
|
-
res: 'res',
|
|
19
|
-
err: 'err',
|
|
20
|
-
responseTime: 'taken(ms)',
|
|
21
|
-
},
|
|
22
|
-
formatters: (0, formatters_js_1.getOtelFormatters)(spanIdKey, traceIdKey),
|
|
23
|
-
serializers: (0, serializers_js_1.getSerializers)(),
|
|
24
|
-
redact: {
|
|
25
|
-
paths: [
|
|
26
|
-
'password',
|
|
27
|
-
'reqBody.password',
|
|
28
|
-
'user.password',
|
|
29
|
-
'reqBody.user.password',
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
genReqId: function (req, res) {
|
|
33
|
-
const reqId = req.id ?? req.headers['x-request-id'];
|
|
34
|
-
if (reqId)
|
|
35
|
-
return reqId;
|
|
36
|
-
const id = (0, node_crypto_1.randomUUID)();
|
|
37
|
-
res.setHeader('X-Request-Id', id);
|
|
38
|
-
return id;
|
|
39
|
-
},
|
|
40
|
-
customLogLevel(_, res, err) {
|
|
41
|
-
if (res.statusCode >= 400 && res.statusCode < 500) {
|
|
42
|
-
return 'warn';
|
|
43
|
-
}
|
|
44
|
-
else if (res.statusCode >= 500 || err) {
|
|
45
|
-
return 'error';
|
|
46
|
-
}
|
|
47
|
-
else if (res.statusCode >= 300 && res.statusCode < 400) {
|
|
48
|
-
return 'silent';
|
|
49
|
-
}
|
|
50
|
-
return 'info';
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=options.js.map
|
package/dist/options.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;;;AAcA,8C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,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC;gBAC1D,OAAO,QAAQ,CAAC;YACjB,CAAC;YAED,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/serializers.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serializers.d.ts","sourceRoot":"","sources":["../src/serializers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAWzC,wBAAgB,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAyB7D"}
|
package/dist/serializers.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSerializers = getSerializers;
|
|
4
|
-
function getSerializers() {
|
|
5
|
-
return {
|
|
6
|
-
req(req) {
|
|
7
|
-
const request = req.raw;
|
|
8
|
-
return {
|
|
9
|
-
id: req.id,
|
|
10
|
-
method: req.method,
|
|
11
|
-
url: req.url,
|
|
12
|
-
headers: request.headers,
|
|
13
|
-
query: request.query,
|
|
14
|
-
body: request.body,
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
res(response) {
|
|
18
|
-
const { statusCode: status, ...serialized } = response;
|
|
19
|
-
return Object.assign({ status }, serialized);
|
|
20
|
-
},
|
|
21
|
-
err(err) {
|
|
22
|
-
return err;
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=serializers.js.map
|
package/dist/serializers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serializers.js","sourceRoot":"","sources":["../src/serializers.ts"],"names":[],"mappings":";;AAYA,wCAyBC;AAzBD,SAAgB,cAAc;IAC7B,OAAO;QACN,GAAG,CAAC,GAAsB;YACzB,MAAM,OAAO,GAAG,GAAG,CAAC,GAEnB,CAAC;YAEF,OAAO;gBACN,EAAE,EAAE,GAAG,CAAC,EAAE;gBACV,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,IAAI,EAAE,OAAO,CAAC,IAAI;aAClB,CAAC;QACH,CAAC;QACD,GAAG,CAAC,QAA4B;YAC/B,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,GAAG,QAAQ,CAAC;YAEvD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC;QAC9C,CAAC;QACD,GAAG,CAAC,GAAoB;YACvB,OAAO,GAAG,CAAC;QACZ,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/streams.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import pino from 'pino';
|
|
2
|
-
export declare function createPrettyStreamEntry(_app: string, level: pino.Level): pino.StreamEntry;
|
|
3
|
-
export declare function createLokiStreamEntry(app: string, level: pino.Level, host: string): pino.StreamEntry;
|
|
4
|
-
export declare function createFileStreamEntry(_app: string, level: pino.Level, filepath: string): pino.StreamEntry;
|
|
5
|
-
export declare function getMultiDestinationStream(app: string, level?: pino.Level, filepath?: string, loki?: string): pino.MultiStreamRes;
|
|
6
|
-
//# sourceMappingURL=streams.d.ts.map
|
package/dist/streams.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../src/streams.ts"],"names":[],"mappings":"AAGA,OAAO,IAAI,MAAM,MAAM,CAAC;AAQxB,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,IAAI,CAAC,KAAK,GACf,IAAI,CAAC,WAAW,CAQlB;AAMD,wBAAgB,qBAAqB,CACpC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,IAAI,EAAE,MAAM,GACV,IAAI,CAAC,WAAW,CAWlB;AAMD,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,QAAQ,EAAE,MAAM,GACd,IAAI,CAAC,WAAW,CAWlB;AAMD,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,IAAI,CAAC,KAAc,EAC1B,QAAQ,CAAC,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,GACX,IAAI,CAAC,cAAc,CAOrB"}
|
package/dist/streams.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createPrettyStreamEntry = createPrettyStreamEntry;
|
|
7
|
-
exports.createLokiStreamEntry = createLokiStreamEntry;
|
|
8
|
-
exports.createFileStreamEntry = createFileStreamEntry;
|
|
9
|
-
exports.getMultiDestinationStream = getMultiDestinationStream;
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const pino_1 = __importDefault(require("pino"));
|
|
12
|
-
const pino_loki_1 = require("pino-loki");
|
|
13
|
-
const pino_pretty_1 = __importDefault(require("pino-pretty"));
|
|
14
|
-
const rotating_file_stream_1 = require("rotating-file-stream");
|
|
15
|
-
function createPrettyStreamEntry(_app, level) {
|
|
16
|
-
const stream = (0, pino_pretty_1.default)({
|
|
17
|
-
translateTime: false,
|
|
18
|
-
hideObject: false,
|
|
19
|
-
colorize: true,
|
|
20
|
-
});
|
|
21
|
-
return { level, stream };
|
|
22
|
-
}
|
|
23
|
-
function createLokiStreamEntry(app, level, host) {
|
|
24
|
-
console.log('createLokiStreamEntry', app, level, host);
|
|
25
|
-
const stream = (0, pino_loki_1.pinoLoki)({
|
|
26
|
-
replaceTimestamp: true,
|
|
27
|
-
batching: true,
|
|
28
|
-
interval: 5,
|
|
29
|
-
host,
|
|
30
|
-
labels: { app, service: app },
|
|
31
|
-
});
|
|
32
|
-
return { level, stream };
|
|
33
|
-
}
|
|
34
|
-
function createFileStreamEntry(_app, level, filepath) {
|
|
35
|
-
const { base, dir } = node_path_1.default.parse(filepath);
|
|
36
|
-
const stream = (0, rotating_file_stream_1.createStream)(base, {
|
|
37
|
-
size: '1G',
|
|
38
|
-
interval: '1d',
|
|
39
|
-
compress: 'gzip',
|
|
40
|
-
path: dir,
|
|
41
|
-
});
|
|
42
|
-
return { level, stream };
|
|
43
|
-
}
|
|
44
|
-
function getMultiDestinationStream(app, level = 'info', filepath, loki) {
|
|
45
|
-
const entries = [createPrettyStreamEntry(app, level)];
|
|
46
|
-
if (filepath)
|
|
47
|
-
entries.push(createFileStreamEntry(app, level, filepath));
|
|
48
|
-
if (loki)
|
|
49
|
-
entries.push(createLokiStreamEntry(app, level, loki));
|
|
50
|
-
return pino_1.default.multistream(entries);
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=streams.js.map
|
package/dist/streams.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streams.js","sourceRoot":"","sources":["../src/streams.ts"],"names":[],"mappings":";;;;;AAWA,0DAWC;AAMD,sDAeC;AAMD,sDAeC;AAMD,8DAYC;AAjFD,0DAA6B;AAE7B,gDAAwB;AACxB,yCAAqC;AACrC,8DAAqC;AACrC,+DAAoD;AAKpD,SAAgB,uBAAuB,CACtC,IAAY,EACZ,KAAiB;IAEjB,MAAM,MAAM,GAAG,IAAA,qBAAU,EAAC;QACzB,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;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