{"_id":"@caleblawson/loggers","name":"@caleblawson/loggers","dist-tags":{"latest":"0.10.2"},"versions":{"0.10.2":{"name":"@caleblawson/loggers","version":"0.10.2","description":"A collection of logging transport implementations for Mastra, extending the `LoggerTransport` class from `@mastra/core`.","type":"module","types":"./dist/index.d.ts","main":"./dist/index.js","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"./file":{"import":{"types":"./dist/file/index.d.ts","default":"./dist/file/index.js"},"require":{"types":"./dist/file/index.d.cts","default":"./dist/file/index.cjs"}},"./upstash":{"import":{"types":"./dist/upstash/index.d.ts","default":"./dist/upstash/index.js"},"require":{"types":"./dist/upstash/index.d.cts","default":"./dist/upstash/index.cjs"}},"./package.json":"./package.json"},"keywords":[],"author":"","license":"Elastic-2.0","dependencies":{"pino":"^9.7.0","pino-pretty":"^13.0.0"},"devDependencies":{"@microsoft/api-extractor":"^7.52.8","@types/node":"^20.19.0","eslint":"^9.28.0","tsup":"^8.5.0","typescript":"^5.8.3","vitest":"^3.2.3","@internal/lint":"0.0.13","@mastra/core":"npm:@caleblawson/core@0.10.7-alpha.0"},"peerDependencies":{"@mastra/core":">=0.10.4-0 <0.11.0"},"scripts":{"build":"tsup src/index.ts src/file/index.ts src/upstash/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting","build:watch":"pnpm build --watch","test":"vitest run","lint":"eslint ."},"gitHead":"c31e90130a5c9765c23f688ecea70adc6164543d","_id":"@caleblawson/loggers@0.10.2","_integrity":"sha512-YAQzcdcKUjI5bzqkpb5j1BpKACcFQiR5aRKEX2zCE9NlofLWaUtPytTW1mIKengjOmd09OWxhBYhM3oFZr/A0Q==","_resolved":"C:\\Users\\caleb\\AppData\\Local\\Temp\\512ffbe0e2488081614ce504ca2b5103\\caleblawson-loggers-0.10.2.tgz","_from":"file:caleblawson-loggers-0.10.2.tgz","_nodeVersion":"21.2.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-YAQzcdcKUjI5bzqkpb5j1BpKACcFQiR5aRKEX2zCE9NlofLWaUtPytTW1mIKengjOmd09OWxhBYhM3oFZr/A0Q==","shasum":"399543562c756641fb0c120387740c3b3db773c0","tarball":"https://registry.npmjs.org/@caleblawson/loggers/-/loggers-0.10.2.tgz","fileCount":17,"unpackedSize":42340,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDk0Fyy34Zvh5GzPbv2WBUVwNlkTnxCJgzdj/k1JngRxwIhAJG8YanKE5FxjMfI8DCyRGkMr8t/CjKUxu0RIuoO5GzA"}]},"_npmUser":{"name":"caleblawson","email":"caleb.lawson@dynapt.com","actor":{"name":"caleblawson","email":"caleb.lawson@dynapt.com","type":"user"}},"directories":{},"maintainers":[{"name":"caleblawson","email":"caleb.lawson@dynapt.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/loggers_0.10.2_1750378231759_0.7591468798417822"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-20T00:10:31.666Z","0.10.2":"2025-06-20T00:10:31.917Z","modified":"2025-06-20T00:10:32.195Z"},"maintainers":[{"name":"caleblawson","email":"caleb.lawson@dynapt.com"}],"description":"A collection of logging transport implementations for Mastra, extending the `LoggerTransport` class from `@mastra/core`.","keywords":[],"license":"Elastic-2.0","readme":"# @mastra/loggers\r\n\r\nA collection of logging transport implementations for Mastra, extending the `LoggerTransport` class from `@mastra/core`.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @mastra/loggers\r\n```\r\n\r\n## Available Transports\r\n\r\n### File Transport\r\n\r\nA transport that writes logs to a local file system.\r\n\r\n```typescript\r\nimport { FileTransport } from '@mastra/loggers';\r\n\r\nconst fileLogger = new FileTransport({\r\n  path: '/path/to/logs/app.log',\r\n});\r\n```\r\n\r\n#### Configuration\r\n\r\n- `path`: Absolute path to the log file (must exist)\r\n\r\n#### Features\r\n\r\n- Append-mode logging\r\n- Automatic stream cleanup\r\n- JSON log parsing\r\n- Query logs by run ID\r\n- Stream-based implementation\r\n\r\n### Upstash Transport\r\n\r\nA transport that sends logs to Upstash Redis with batching and auto-trimming capabilities.\r\n\r\n```typescript\r\nimport { UpstashTransport } from '@mastra/loggers';\r\n\r\nconst upstashLogger = new UpstashTransport({\r\n  upstashUrl: 'https://your-instance.upstash.io',\r\n  upstashToken: 'your-token',\r\n  listName: 'application-logs', // optional\r\n  maxListLength: 10000, // optional\r\n  batchSize: 100, // optional\r\n  flushInterval: 10000, // optional\r\n});\r\n```\r\n\r\n#### Configuration\r\n\r\nRequired:\r\n\r\n- `upstashUrl`: Your Upstash Redis instance URL\r\n- `upstashToken`: Your Upstash authentication token\r\n\r\nOptional:\r\n\r\n- `listName`: Redis list name for logs (default: 'application-logs')\r\n- `maxListLength`: Maximum number of logs to keep (default: 10000)\r\n- `batchSize`: Number of logs to send in one batch (default: 100)\r\n- `flushInterval`: Milliseconds between flush attempts (default: 10000)\r\n\r\n#### Features\r\n\r\n- Batched log writing\r\n- Automatic log rotation (LTRIM)\r\n- Configurable buffer size\r\n- Automatic retry on failure\r\n- Query logs by run ID\r\n- JSON log formatting\r\n- Timestamp auto-injection\r\n- Graceful shutdown with final flush\r\n\r\n## Usage with Mastra Core\r\n\r\nBoth transports implement the `LoggerTransport` interface from `@mastra/core`:\r\n\r\n```typescript\r\nimport { Logger } from '@mastra/core/logger';\r\nimport { FileTransport, UpstashTransport } from '@mastra/loggers';\r\n\r\n// Create transports\r\nconst fileTransport = new FileTransport({\r\n  path: '/var/log/app.log',\r\n});\r\n\r\nconst upstashTransport = new UpstashTransport({\r\n  upstashUrl: process.env.UPSTASH_URL!,\r\n  upstashToken: process.env.UPSTASH_TOKEN!,\r\n});\r\n\r\n// Create logger with multiple transports\r\nconst logger = new Logger({\r\n  transports: [fileTransport, upstashTransport],\r\n});\r\n\r\n// Log messages\r\nlogger.info('Hello world', { metadata: 'value' });\r\n\r\n// Query logs\r\nconst allLogs = await fileTransport.getLogs();\r\nconst runLogs = await upstashTransport.getLogsByRunId({ runId: 'abc-123' });\r\n```\r\n\r\n## Log Message Format\r\n\r\nBoth transports handle log messages in JSON format with the following structure:\r\n\r\n```typescript\r\ninterface BaseLogMessage {\r\n  time?: number; // Timestamp (auto-injected if not present)\r\n  level?: string; // Log level\r\n  msg?: {\r\n    // Message content\r\n    runId?: string; // Optional run ID for grouping logs\r\n    [key: string]: any;\r\n  };\r\n  [key: string]: any;\r\n}\r\n```\r\n\r\n## Error Handling\r\n\r\nBoth transports include robust error handling:\r\n\r\n- File Transport:\r\n\r\n  - Validates file path existence\r\n  - Handles stream errors\r\n  - Graceful cleanup on destroy\r\n\r\n- Upstash Transport:\r\n  - Validates required configuration\r\n  - Retries failed batches\r\n  - Buffers logs during outages\r\n  - Graceful shutdown with final flush\r\n\r\n## Related Links\r\n\r\n- [Upstash Redis Documentation](https://docs.upstash.com/redis)\r\n- [Node.js Stream Documentation](https://nodejs.org/api/stream.html)\r\n","readmeFilename":"README.md","_rev":"1-d10ce3ab10f5e643f6ab0ff90e194403"}