Sending Logs

Send structured events to NextLogs using your project’s apiKey.

Event schema (starter)

At minimum, each event should include:

  • message (string)
  • level (e.g. info, error)
  • service (string)
{
  "message": "User signed in",
  "level": "info",
  "service": "auth",
  "tags": ["auth", "login"]
}

Example: Node.js

type LogEvent = {
  message: string;
  level: "info" | "warn" | "error";
  service: string;
  tags?: string[];
};

export async function sendLog(event: LogEvent) {
  const res = await fetch("https://api.nextlogs.example/v1/logs", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.NEXTLOGS_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(event),
  });

  if (!res.ok) {
    throw new Error(`NextLogs ingest failed: ${res.status}`);
  }
}