@efebia/pino-mongodb 1.0.2 → 1.0.4
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 +72 -0
- package/package.json +7 -2
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @efebia/pino-mongodb
|
|
2
|
+
|
|
3
|
+
Pino transport that writes logs to MongoDB, with support for batched bulk inserts.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @efebia/pino-mongodb
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Batched mode (default)
|
|
14
|
+
|
|
15
|
+
Logs are queued and flushed to MongoDB in bulk at a configurable interval or when the batch size is reached.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import pino from 'pino';
|
|
19
|
+
|
|
20
|
+
const logger = pino({
|
|
21
|
+
transport: {
|
|
22
|
+
target: '@efebia/pino-mongodb',
|
|
23
|
+
options: {
|
|
24
|
+
uri: 'mongodb://localhost:27017/mydb',
|
|
25
|
+
collection: 'logs',
|
|
26
|
+
queueOptions: {
|
|
27
|
+
interval: 2000, // flush every 2 seconds
|
|
28
|
+
maxMessages: 50, // or when 50 messages have accumulated
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
logger.info('Hello MongoDB');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Immediate mode
|
|
38
|
+
|
|
39
|
+
Each log entry is inserted individually as it arrives.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const logger = pino({
|
|
43
|
+
transport: {
|
|
44
|
+
target: '@efebia/pino-mongodb',
|
|
45
|
+
options: {
|
|
46
|
+
uri: 'mongodb://localhost:27017/mydb',
|
|
47
|
+
collection: 'logs',
|
|
48
|
+
immediate: true,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Options
|
|
55
|
+
|
|
56
|
+
| Option | Type | Default | Description |
|
|
57
|
+
|--------|------|---------|-------------|
|
|
58
|
+
| `uri` | `string` | `'mongodb://localhost:27017/logs'` | MongoDB connection URI |
|
|
59
|
+
| `database` | `string` | _(from URI)_ | Database name (overrides the one in the URI) |
|
|
60
|
+
| `collection` | `string` | `'logs'` | Collection name |
|
|
61
|
+
| `immediate` | `true` | — | Enable immediate (non-batched) mode |
|
|
62
|
+
| `clientOptions` | `MongoClientOptions` | — | Options forwarded to the `MongoClient` constructor |
|
|
63
|
+
| `onError` | `(messages, error) => void` | — | Called when a bulk write fails (batched mode only) |
|
|
64
|
+
| `queueOptions.interval` | `number` | `1000` | Flush interval in milliseconds (batched mode) |
|
|
65
|
+
| `queueOptions.maxMessages` | `number` | `10` | Flush when this many messages have queued (batched mode) |
|
|
66
|
+
| `queueOptions.cache` | `unknown[]` | `[]` | Initial cache (rarely needed) |
|
|
67
|
+
|
|
68
|
+
`immediate` and `queueOptions` are mutually exclusive — use one or the other.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@efebia/pino-mongodb",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"mongodb": "^6.15.0",
|
|
@@ -16,5 +16,10 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc"
|
|
18
18
|
},
|
|
19
|
-
"main": "./lib"
|
|
19
|
+
"main": "./lib",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/efebia-com/be-libs.git",
|
|
23
|
+
"directory": "packages/pino-mongodb"
|
|
24
|
+
}
|
|
20
25
|
}
|