npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mastra/loggers

v0.1.12

Published

A collection of logging transport implementations for Mastra, extending the `LoggerTransport` class from `@mastra/core`.

Downloads

3,274

Readme

@mastra/loggers

A collection of logging transport implementations for Mastra, extending the LoggerTransport class from @mastra/core.

Installation

npm install @mastra/loggers

Available Transports

File Transport

A transport that writes logs to a local file system.

import { FileTransport } from '@mastra/loggers';

const fileLogger = new FileTransport({
  path: '/path/to/logs/app.log',
});

Configuration

  • path: Absolute path to the log file (must exist)

Features

  • Append-mode logging
  • Automatic stream cleanup
  • JSON log parsing
  • Query logs by run ID
  • Stream-based implementation

Upstash Transport

A transport that sends logs to Upstash Redis with batching and auto-trimming capabilities.

import { UpstashTransport } from '@mastra/loggers';

const upstashLogger = new UpstashTransport({
  upstashUrl: 'https://your-instance.upstash.io',
  upstashToken: 'your-token',
  listName: 'application-logs', // optional
  maxListLength: 10000, // optional
  batchSize: 100, // optional
  flushInterval: 10000, // optional
});

Configuration

Required:

  • upstashUrl: Your Upstash Redis instance URL
  • upstashToken: Your Upstash authentication token

Optional:

  • 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)

Features

  • Batched log writing
  • Automatic log rotation (LTRIM)
  • Configurable buffer size
  • Automatic retry on failure
  • Query logs by run ID
  • JSON log formatting
  • Timestamp auto-injection
  • Graceful shutdown with final flush

Usage with Mastra Core

Both transports implement the LoggerTransport interface from @mastra/core:

import { Logger } from '@mastra/core/logger';
import { FileTransport, UpstashTransport } from '@mastra/loggers';

// Create transports
const fileTransport = new FileTransport({
  path: '/var/log/app.log',
});

const upstashTransport = new UpstashTransport({
  upstashUrl: process.env.UPSTASH_URL!,
  upstashToken: process.env.UPSTASH_TOKEN!,
});

// Create logger with multiple transports
const logger = new Logger({
  transports: [fileTransport, upstashTransport],
});

// Log messages
logger.info('Hello world', { metadata: 'value' });

// Query logs
const allLogs = await fileTransport.getLogs();
const runLogs = await upstashTransport.getLogsByRunId({ runId: 'abc-123' });

Log Message Format

Both transports handle log messages in JSON format with the following structure:

interface BaseLogMessage {
  time?: number; // Timestamp (auto-injected if not present)
  level?: string; // Log level
  msg?: {
    // Message content
    runId?: string; // Optional run ID for grouping logs
    [key: string]: any;
  };
  [key: string]: any;
}

Error Handling

Both transports include robust error handling:

  • File Transport:

    • Validates file path existence
    • Handles stream errors
    • Graceful cleanup on destroy
  • Upstash Transport:

    • Validates required configuration
    • Retries failed batches
    • Buffers logs during outages
    • Graceful shutdown with final flush

Related Links