|
2 | 2 |
|
3 | 3 | A stream to send [Pino](https://github.com/pinojs/pino) events to [Seq](https://datalust.co/seq). Tested with Node.js versions 18.x and up. |
4 | 4 |
|
| 5 | +**Now written in TypeScript** with automatic type definitions and full ES Module support! |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install pino-seq |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
5 | 15 | Use the `createStream()` method to create a Pino stream configuration, passing `serverUrl`, `apiKey` and batching parameters. |
6 | 16 |
|
7 | | -```js |
| 17 | +This example works in both JavaScript and TypeScript projects: |
| 18 | + |
| 19 | +```javascript |
8 | 20 | import pino from 'pino'; |
9 | | -import pinoToSeq from 'pino-seq'; |
| 21 | +import { createStream } from 'pino-seq'; |
10 | 22 |
|
11 | | -let stream = pinoToSeq.createStream({ serverUrl: 'http://localhost:5341' }); |
12 | | -let logger = pino({ name: 'pino-seq example' }, stream); |
| 23 | +// Create a stream to Seq |
| 24 | +const stream = createStream({ |
| 25 | + serverUrl: 'http://localhost:5341', |
| 26 | + apiKey: 'your-api-key' // optional |
| 27 | +}); |
13 | 28 |
|
| 29 | +// Create a Pino logger |
| 30 | +const logger = pino({ name: 'pino-seq example' }, stream); |
| 31 | + |
| 32 | +// Log some messages |
14 | 33 | logger.info('Hello Seq, from Pino'); |
15 | 34 |
|
16 | | -let frLogger = logger.child({ lang: 'fr' }); |
| 35 | +// Child loggers work too |
| 36 | +const frLogger = logger.child({ lang: 'fr' }); |
17 | 37 | frLogger.warn('au reviour'); |
| 38 | + |
| 39 | +// Flush logs before exit |
| 40 | +await stream.flush(); |
18 | 41 | ``` |
19 | 42 |
|
20 | | -### Acknowledgements |
| 43 | +For TypeScript projects with explicit typing: |
| 44 | + |
| 45 | +```typescript |
| 46 | +import { createStream, PinoSeqStreamConfig } from 'pino-seq'; |
| 47 | + |
| 48 | +const config: PinoSeqStreamConfig = { |
| 49 | + serverUrl: 'http://localhost:5341', |
| 50 | + // ... see Configuration section below for all options |
| 51 | +}; |
| 52 | +const stream = createStream(config); |
| 53 | +``` |
| 54 | + |
| 55 | +## Configuration |
| 56 | + |
| 57 | +The `createStream()` function accepts a configuration object with the following properties: |
| 58 | + |
| 59 | +- `serverUrl` (string): The URL of your Seq server |
| 60 | +- `apiKey` (string, optional): API key for authentication |
| 61 | +- `logOtherAs` (string, optional): Log level for unstructured messages ('Verbose', 'Debug', 'Information', 'Warning', 'Error', 'Fatal') |
| 62 | +- `additionalProperties` (object, optional): Additional properties to add to all log events |
| 63 | +- `maxBatchingTime` (number, optional): Maximum time in milliseconds to wait before sending a batch |
| 64 | +- `eventSizeLimit` (number, optional): Maximum size of a single event |
| 65 | +- `batchSizeLimit` (number, optional): Maximum size of a batch |
| 66 | +- `onError` (function, optional): Error handler callback |
| 67 | + |
| 68 | +## Acknowledgements |
21 | 69 |
|
22 | 70 | Originally by Simi Hartstein and published as `simihartstein/pino-seq`; maintainership transferred to Datalust at version 0.5. |
0 commit comments