@mastra/loggers 1.3.1-alpha.0 → 1.3.1-alpha.1
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 +40 -105
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mastra/loggers
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Logger and logging transport implementations for Mastra. The package includes a structured Pino logger plus file, HTTP, and Upstash transports that extend `LoggerTransport` from `@mastra/core/logger`.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,138 +8,73 @@ A collection of logging transport implementations for Mastra, extending the `Log
|
|
|
8
8
|
npm install @mastra/loggers
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
A transport that writes logs to a local file system.
|
|
13
|
+
Create a logger with one or more named transports and pass it to Mastra:
|
|
16
14
|
|
|
17
15
|
```typescript
|
|
18
|
-
import {
|
|
16
|
+
import { Logger } from '@mastra/core/logger';
|
|
17
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
18
|
+
import { FileTransport } from '@mastra/loggers/file';
|
|
19
|
+
import { UpstashTransport } from '@mastra/loggers/upstash';
|
|
19
20
|
|
|
20
|
-
const
|
|
21
|
-
|
|
21
|
+
const logger = new Logger({
|
|
22
|
+
transports: [
|
|
23
|
+
new FileTransport({ path: '/var/log/my-app.log' }),
|
|
24
|
+
new UpstashTransport({
|
|
25
|
+
upstashUrl: process.env.UPSTASH_URL!,
|
|
26
|
+
upstashToken: process.env.UPSTASH_TOKEN!,
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
22
29
|
});
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
#### Configuration
|
|
26
|
-
|
|
27
|
-
- `path`: Absolute path to the log file (must exist)
|
|
28
|
-
|
|
29
|
-
#### Features
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
- Automatic stream cleanup
|
|
33
|
-
- JSON log parsing
|
|
34
|
-
- Query logs by run ID
|
|
35
|
-
- Stream-based implementation
|
|
36
|
-
|
|
37
|
-
### Upstash Transport
|
|
38
|
-
|
|
39
|
-
A transport that sends logs to Upstash Redis with batching and auto-trimming capabilities.
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
import { UpstashTransport } from '@mastra/loggers';
|
|
43
|
-
|
|
44
|
-
const upstashLogger = new UpstashTransport({
|
|
45
|
-
upstashUrl: 'https://your-instance.upstash.io',
|
|
46
|
-
upstashToken: 'your-token',
|
|
47
|
-
listName: 'application-logs', // optional
|
|
48
|
-
maxListLength: 10000, // optional
|
|
49
|
-
batchSize: 100, // optional
|
|
50
|
-
flushInterval: 10000, // optional
|
|
51
|
-
});
|
|
31
|
+
export const mastra = new Mastra({ logger });
|
|
52
32
|
```
|
|
53
33
|
|
|
54
|
-
|
|
34
|
+
## Documentation
|
|
55
35
|
|
|
56
|
-
|
|
36
|
+
### Logger
|
|
57
37
|
|
|
58
|
-
|
|
59
|
-
- `upstashToken`: Your Upstash authentication token
|
|
38
|
+
`Logger` combines one or more `LoggerTransport` implementations and can be passed directly to the Mastra configuration. It supports standard log levels and sends each structured log record to the configured transports, which can persist, batch, or forward the data to external systems.
|
|
60
39
|
|
|
61
|
-
|
|
40
|
+
### File transport
|
|
62
41
|
|
|
63
|
-
|
|
64
|
-
- `maxListLength`: Maximum number of logs to keep (default: 10000)
|
|
65
|
-
- `batchSize`: Number of logs to send in one batch (default: 100)
|
|
66
|
-
- `flushInterval`: Milliseconds between flush attempts (default: 10000)
|
|
42
|
+
`FileTransport` appends structured logs to an existing local file. It can list logs, query by run ID, stream records, and clean up the underlying write stream when destroyed.
|
|
67
43
|
|
|
68
|
-
|
|
44
|
+
```typescript
|
|
45
|
+
import { FileTransport } from '@mastra/loggers/file';
|
|
69
46
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
- Automatic retry on failure
|
|
74
|
-
- Query logs by run ID
|
|
75
|
-
- JSON log formatting
|
|
76
|
-
- Timestamp auto-injection
|
|
77
|
-
- Graceful shutdown with final flush
|
|
47
|
+
const fileTransport = new FileTransport({ path: '/var/log/my-app.log' });
|
|
48
|
+
const runLogs = await fileTransport.listLogsByRunId({ runId: 'run-123' });
|
|
49
|
+
```
|
|
78
50
|
|
|
79
|
-
|
|
51
|
+
### Upstash transport
|
|
80
52
|
|
|
81
|
-
|
|
53
|
+
`UpstashTransport` batches logs into an Upstash Redis list. Configure the instance URL and token, then optionally set the list name, maximum retained list length, batch size, and flush interval. It trims old records, retries failed batches, and performs a final flush during shutdown.
|
|
82
54
|
|
|
83
55
|
```typescript
|
|
84
|
-
import {
|
|
85
|
-
import { FileTransport, UpstashTransport } from '@mastra/loggers';
|
|
86
|
-
|
|
87
|
-
// Create transports
|
|
88
|
-
const fileTransport = new FileTransport({
|
|
89
|
-
path: '/var/log/app.log',
|
|
90
|
-
});
|
|
56
|
+
import { UpstashTransport } from '@mastra/loggers/upstash';
|
|
91
57
|
|
|
92
58
|
const upstashTransport = new UpstashTransport({
|
|
93
59
|
upstashUrl: process.env.UPSTASH_URL!,
|
|
94
60
|
upstashToken: process.env.UPSTASH_TOKEN!,
|
|
61
|
+
listName: 'application-logs',
|
|
62
|
+
maxListLength: 10_000,
|
|
63
|
+
batchSize: 100,
|
|
64
|
+
flushInterval: 10_000,
|
|
95
65
|
});
|
|
96
|
-
|
|
97
|
-
// Create logger with multiple transports
|
|
98
|
-
const logger = new Logger({
|
|
99
|
-
transports: [fileTransport, upstashTransport],
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// Log messages
|
|
103
|
-
logger.info('Hello world', { metadata: 'value' });
|
|
104
|
-
|
|
105
|
-
// Query logs
|
|
106
|
-
const allLogs = await fileTransport.listLogs();
|
|
107
|
-
const runLogs = await upstashTransport.listLogsByRunId({ runId: 'abc-123' });
|
|
108
66
|
```
|
|
109
67
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
Both transports handle log messages in JSON format with the following structure:
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
interface BaseLogMessage {
|
|
116
|
-
time?: number; // Timestamp (auto-injected if not present)
|
|
117
|
-
level?: string; // Log level
|
|
118
|
-
msg?: {
|
|
119
|
-
// Message content
|
|
120
|
-
runId?: string; // Optional run ID for grouping logs
|
|
121
|
-
[key: string]: any;
|
|
122
|
-
};
|
|
123
|
-
[key: string]: any;
|
|
124
|
-
}
|
|
125
|
-
```
|
|
68
|
+
### HTTP transport
|
|
126
69
|
|
|
127
|
-
|
|
70
|
+
`HttpTransport` sends batches of structured log records to an HTTP endpoint and supports request headers, batching, retry, and flush configuration. Use it for application-specific collectors and hosted logging gateways.
|
|
128
71
|
|
|
129
|
-
|
|
72
|
+
- [`PinoLogger` reference](https://mastra.ai/reference/logging/pino-logger)
|
|
130
73
|
|
|
131
|
-
|
|
132
|
-
- Validates file path existence
|
|
133
|
-
- Handles stream errors
|
|
134
|
-
- Graceful cleanup on destroy
|
|
74
|
+
## Changelog
|
|
135
75
|
|
|
136
|
-
-
|
|
137
|
-
- Validates required configuration
|
|
138
|
-
- Retries failed batches
|
|
139
|
-
- Buffers logs during outages
|
|
140
|
-
- Graceful shutdown with final flush
|
|
76
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/packages/loggers/CHANGELOG.md) for version history and release notes.
|
|
141
77
|
|
|
142
|
-
##
|
|
78
|
+
## Support
|
|
143
79
|
|
|
144
|
-
|
|
145
|
-
- [Node.js Stream Documentation](https://nodejs.org/api/stream.html)
|
|
80
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-loggers
|
|
|
3
3
|
description: Documentation for @mastra/loggers. Use when working with @mastra/loggers APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/loggers"
|
|
6
|
-
version: "1.3.1-alpha.
|
|
6
|
+
version: "1.3.1-alpha.1"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/loggers",
|
|
3
|
-
"version": "1.3.1-alpha.
|
|
3
|
+
"version": "1.3.1-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -76,9 +76,9 @@
|
|
|
76
76
|
"tsx": "^4.23.1",
|
|
77
77
|
"typescript": "^7.0.2",
|
|
78
78
|
"vitest": "4.1.10",
|
|
79
|
-
"@internal/lint": "0.0.129",
|
|
80
79
|
"@internal/types-builder": "0.0.104",
|
|
81
|
-
"@
|
|
80
|
+
"@internal/lint": "0.0.129",
|
|
81
|
+
"@mastra/core": "1.64.0-alpha.7"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
84
|
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|