NuxtHub

Retention & Cleanup

Overview
Configure how long logs are kept and how they are automatically cleaned up with scheduled tasks and cron jobs.

@evlog/nuxthub automatically deletes old events based on your retention policy. No manual cleanup needed.

Configuration

Set the retention period in your nuxt.config.ts:

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@evlog/nuxthub'],

  evlog: {
    retention: '7d', // default
  },
})

Retention Format

The retention value is a number followed by a unit:

UnitDescriptionExample
dDays7d = 7 days
hHours24h = 24 hours
mMinutes60m = 60 minutes

How Cleanup Works

The module registers a Nitro scheduled task (evlog:cleanup) that runs on a cron schedule derived from your retention value. The cron frequency is set to roughly half the retention period:

RetentionCron ScheduleDescription
60m*/30 * * * *Every 30 minutes
24h0 */12 * * *Every 12 hours
7d0 3 * * *Daily at 3:00 AM
30d0 3 * * *Daily at 3:00 AM

The cleanup task deletes all rows in evlog_events where created_at is older than the retention period.

Manual Cleanup

You can trigger cleanup manually via the API endpoint:

curl https://your-app.com/api/_cron/evlog-cleanup

Cron Secret Protection

If the CRON_SECRET environment variable is set, the endpoint requires a Bearer token:

curl -H "Authorization: Bearer your-secret" \
  https://your-app.com/api/_cron/evlog-cleanup

This is recommended for production deployments to prevent unauthorized cleanup triggers.

Vercel Cron

When installing the module with nuxi module add, you'll be prompted to create a vercel.json with the appropriate cron schedule:

vercel.json
{
  "crons": [
    {
      "path": "/api/_cron/evlog-cleanup",
      "schedule": "0 3 * * *"
    }
  ]
}

On Vercel, the CRON_SECRET environment variable is automatically set and validated.

Cloudflare & Other Platforms

On Cloudflare Workers and other platforms, the Nitro scheduled task handles cleanup automatically — no additional cron configuration needed. The task is registered with experimental.tasks enabled in the Nitro config.

Next Steps

  • Overview — Installation and setup
  • Adapters — Send logs to external services alongside NuxtHub storage
  • Pipeline — Batch events for better database performance
Copyright © 2026