Gathering detailed insights and metrics for @caleblawson/loggers
Gathering detailed insights and metrics for @caleblawson/loggers
Gathering detailed insights and metrics for @caleblawson/loggers
Gathering detailed insights and metrics for @caleblawson/loggers
npm install @caleblawson/loggers
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
1
A collection of logging transport implementations for Mastra, extending the LoggerTransport
class from @mastra/core
.
1npm install @mastra/loggers
A transport that writes logs to a local file system.
1import { FileTransport } from '@mastra/loggers'; 2 3const fileLogger = new FileTransport({ 4 path: '/path/to/logs/app.log', 5});
path
: Absolute path to the log file (must exist)A transport that sends logs to Upstash Redis with batching and auto-trimming capabilities.
1import { UpstashTransport } from '@mastra/loggers'; 2 3const upstashLogger = new UpstashTransport({ 4 upstashUrl: 'https://your-instance.upstash.io', 5 upstashToken: 'your-token', 6 listName: 'application-logs', // optional 7 maxListLength: 10000, // optional 8 batchSize: 100, // optional 9 flushInterval: 10000, // optional 10});
Required:
upstashUrl
: Your Upstash Redis instance URLupstashToken
: Your Upstash authentication tokenOptional:
listName
: Redis list name for logs (default: 'application-logs')maxListLength
: Maximum number of logs to keep (default: 10000)batchSize
: Number of logs to send in one batch (default: 100)flushInterval
: Milliseconds between flush attempts (default: 10000)Both transports implement the LoggerTransport
interface from @mastra/core
:
1import { Logger } from '@mastra/core/logger'; 2import { FileTransport, UpstashTransport } from '@mastra/loggers'; 3 4// Create transports 5const fileTransport = new FileTransport({ 6 path: '/var/log/app.log', 7}); 8 9const upstashTransport = new UpstashTransport({ 10 upstashUrl: process.env.UPSTASH_URL!, 11 upstashToken: process.env.UPSTASH_TOKEN!, 12}); 13 14// Create logger with multiple transports 15const logger = new Logger({ 16 transports: [fileTransport, upstashTransport], 17}); 18 19// Log messages 20logger.info('Hello world', { metadata: 'value' }); 21 22// Query logs 23const allLogs = await fileTransport.getLogs(); 24const runLogs = await upstashTransport.getLogsByRunId({ runId: 'abc-123' });
Both transports handle log messages in JSON format with the following structure:
1interface BaseLogMessage { 2 time?: number; // Timestamp (auto-injected if not present) 3 level?: string; // Log level 4 msg?: { 5 // Message content 6 runId?: string; // Optional run ID for grouping logs 7 [key: string]: any; 8 }; 9 [key: string]: any; 10}
Both transports include robust error handling:
File Transport:
Upstash Transport:
No vulnerabilities found.
No security vulnerabilities found.