You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-24Lines changed: 60 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,9 +20,6 @@ import type { LokiOptions } from 'pino-loki'
20
20
const transport =pino.transport<LokiOptions>({
21
21
target: "pino-loki",
22
22
options: {
23
-
batching: true,
24
-
interval: 5,
25
-
26
23
host: 'https://my-loki-instance:3100',
27
24
basicAuth: {
28
25
username: "username",
@@ -102,11 +99,44 @@ If false, errors when sending logs to Loki will be displayed in the console. Def
102
99
103
100
#### `batching`
104
101
105
-
Should logs be sent in batch mode. Defaults to `true`.
102
+
Batching configuration. When enabled, logs are accumulated in a buffer and sent to Loki at regular intervals, reducing the number of HTTP requests. Batching is **enabled by default**.
103
+
104
+
```ts
105
+
// Batching enabled with default options (interval: 5s, maxBufferSize: 10000)
106
+
pinoLoki({ host: '...' })
107
+
108
+
// Batching with custom options
109
+
pinoLoki({
110
+
host: '...',
111
+
batching: {
112
+
interval: 2, // Send logs every 2 seconds
113
+
maxBufferSize: 5000// Keep max 5000 logs in buffer
114
+
}
115
+
})
116
+
117
+
// Batching disabled - logs sent immediately
118
+
pinoLoki({ host: '...', batching: false })
119
+
```
120
+
121
+
##### `batching.interval`
122
+
123
+
The interval at which batched logs are sent, in seconds. Defaults to `5`.
106
124
107
-
####`interval`
125
+
##### `batching.maxBufferSize`
108
126
109
-
The interval at which batched logs are sent in seconds. Defaults to `5`.
127
+
Maximum number of logs to keep in the buffer. When the buffer is full, **oldest logs are dropped** (FIFO) to make room for new ones. Defaults to `10000`.
128
+
129
+
This prevents memory issues (OOM) if Loki becomes unavailable - without this limit, the buffer would grow indefinitely. Set to `0` for unlimited buffer (probably not really recommended).
--headers <headers> Headers to be sent to Loki (Example: "X-Scope-OrgID=your-id,another-header=another-value")
204
-
-b, --batch Should logs be sent in batch mode
205
-
-i, --interval <interval> The interval at which batched logs are sent in seconds
206
-
-t, --timeout <timeout> Timeout for request to Loki
207
-
-s, --silenceErrors If false, errors will be displayed in the console
208
-
-r, --replaceTimestampReplace pino logs timestamps with Date.now()
209
-
-l, --labels <label>Additional labels to be added to all Loki logs
210
-
-a, --convertArrays If true, arrays will be converted to objects
211
-
-pl, --propsLabels <labels>Fields in log line to convert to Loki labels (comma separated values)
212
-
--structuredMetaKey <key> Key in the pino log object that contains structured metadata
213
-
--no-stdout Disable output to stdout
214
-
-h, --help display help for command
228
+
-v, --version Print version number and exit
229
+
-u, --user <user> Loki username
230
+
-p, --password <password> Loki password
231
+
--hostname <hostname> URL for Loki (default: http://localhost:3100)
232
+
--endpoint <endpoint> Path to the Loki push API (default: /loki/api/v1/push)
233
+
--headers <headers> Headers to be sent to Loki (Example: "X-Scope-OrgID=your-id,another=value")
234
+
-b, --batchingShould logs be sent in batch mode (default: true)
235
+
-i, --batching-interval <interval> The interval at which batched logs are sent in seconds (default: 5)
236
+
--batching-max-buffer-size <size> Maximum number of logs to buffer (default: 10000, 0 for unlimited)
237
+
-t, --timeout <timeout> Timeout for request to Loki in ms (default: 2000)
238
+
-s, --silenceErrors If set, errors will not be displayed in the console
239
+
-r, --replaceTimestamp Replace pino logs timestamps with Date.now()
240
+
-l, --labels <label> Additional labels to be added to all Loki logs (JSON)
241
+
--convertArrays If set, arrays will be converted to objects
242
+
--propsLabels <labels> Fields in log line to convert to Loki labels (comma separated)
243
+
--structuredMetaKey <key>Key in the pino log object that contains structured metadata
244
+
-h, --help Print this help message and exit
215
245
```
216
246
217
247
## Examples
@@ -270,7 +300,13 @@ And you should be good to go! You can check our [full example](./examples/adonis
270
300
Out-of-order Loki errors can occur due to the asynchronous nature of Pino. The fix to this is to allow for out-of-order logs in the Loki configuration. The reason why Loki doesn't have this enabled by default is because Promtail accounts for ordering constraints, however the same issue can also happen with promtail in high-load or when working with distributed networks.
271
301
272
302
## Dropped logs
273
-
If any network issues occur, the logs can be dropped. The recommendation is therefore to implement a failover solution, this will vary greatly from system to system.
303
+
304
+
Logs can be dropped in two scenarios:
305
+
306
+
1.**Network issues**: If Loki is unreachable, logs in the current batch will be lost.
307
+
2.**Buffer overflow**: When batching is enabled and the buffer reaches `maxBufferSize` (default: 10,000), the oldest logs are dropped to make room for new ones. This prevents memory exhaustion if Loki becomes unavailable for an extended period.
308
+
309
+
For critical applications, consider implementing a failover solution or adjusting `maxBufferSize` based on your memory constraints and acceptable data loss.
274
310
275
311
## Node v18+ Required
276
312
As the pino-loki library uses the native Node fetch, any consumer must be using a version of Node greater than v18.0.0.
0 commit comments