Guides / Monitoring
Cron jobs fail silently. You set one up to charge trials, expire free accounts, or send digest emails — and then it quietly stops working for a week until a user complains.
Log the result at the end of every job run. Two events: one on success, one on failure.
import { init } from "logit";
const logit = init({ token: process.env.LOGIT_API_KEY! });
async function runDailyDigest() {
const start = Date.now();
try {
// ... your job logic
const sent = await sendDigestEmails();
await logit.now("cron", {
event: "Daily digest sent ✅",
description: `${sent} emails sent`,
icon: "✅",
notify: false,
tags: { job: "daily-digest", status: "success" },
metadata: { sent, duration: Date.now() - start },
});
} catch (err) {
const error = err instanceof Error ? err : new Error(String(err));
await logit.now("cron", {
event: "Daily digest FAILED ❌",
description: error.message,
icon: "❌",
notify: true,
tags: { job: "daily-digest", status: "failed" },
metadata: { error: error.message, duration: Date.now() - start },
});
}
}
import cron from "node-cron";
cron.schedule("0 9 * * *", runDailyDigest); // every day at 9am
- name: Notify success
if: success()
run: |
curl -X POST https://api.logit.now/api/ingest \
-H "Authorization: Bearer ${{ secrets.LOGIT_API_KEY }}" \
-H "Content-Type: application/json" \
-d '{"channel":"cron","event":"Job succeeded","icon":"✅","notify":false}'
notify: false on success — you don't need a ping every time it works. Set notify: true only on failure.duration field to metadata so you can spot jobs that are slowing down over time.Try LogIt free
7-day trial. No credit card required.