SDK Configuration
Initialize OneMinute Logs
Initialize OneMinute Logs once when your application starts.
After initialization, you can import the logger anywhere in your project and start sending events.
Create a logger
// lib/logs.ts
import { createLogger } from "@oneminutelogs/next";
export const log = createLogger({
apiKey: process.env.ONE_MINUTE_LOGS_API_KEY!,
projectName: "my-next-app",
environment: process.env.NODE_ENV ?? "development",
});Configuration options
| Option | Required | Description |
|---|---|---|
| apiKey | Yes | Your OneMinute Logs API key. |
| projectName | Yes | The project these events belong to. Normalized server-side (lowercased, trimmed) — reuse the same string to keep the same project. |
| serviceName | No | The service emitting the events. Defaults to projectName. Set it when one project has multiple services (api, worker, cron). |
| environment | No | Environment name (development, staging, production). Defaults to NODE_ENV, then development. |
| serviceVersion | No | Your app version. Added to the event resource as service.version. |
| defaultAttributes | No | Attributes merged into every event. Per-call attributes win on conflict. |
Using the logger
Once configured, import it anywhere.
import { log } from "@/lib/logs";Now you're ready to send events.
Important
Do not call log.info(), log.error(), or any other logging method from client-side or frontend code. Keep your logger on the server so your API key stays private.
Best practices
Initialize only once
Create a single logger instance and reuse it throughout your application.
Good
export const log = createLogger({...});Don't
createLogger({...});
createLogger({...});
createLogger({...});Never hardcode your API key
Always load it from environment variables.
apiKey: process.env.ONE_MINUTE_LOGS_API_KEYUse a meaningful project name
projectName is your logical product. Use serviceName to distinguish services inside it.
Good
projectName: "becodemy"
serviceName: "billing-api"
serviceName: "reconcile-worker"
Avoid
projectName: "app"
projectName: "test"
projectName: "project"
Set the correct environment
environment: "production"
environment: "staging"
environment: "development"This makes filtering events much easier later.
What happens after initialization?
Once the logger is initialized, OneMinute Logs automatically:
- Authenticates every request using your API key.
- Buffers events in memory and flushes them in one batch every 2 seconds.
- Retries a failed batch once, then drops it (bounded 10,000-event buffer so an outage can't grow memory).
- Flushes on SIGINT / SIGTERM / process exit so nothing is lost on shutdown.
You only need to call log.info(), log.error(), or the other level methods. See Event Fields for the full event shape.
No manual setup required
Once initialized, OneMinute Logs automatically batches events, retries failed requests, and flushes them in the background. There are no background workers, queues, or cron jobs for you to configure.
What's next?
Now that your logger is configured, let's send your first production event.