JavaScript Configuration
Configure logstack-js — environments, captureConsole, batching, retries, and more.
JavaScript configuration
Deep-dive for logstack-js. For other languages see Go configuration and Python configuration.
Full configuration
Configuration Options
apiKey (required)
Your project API key from the Logstack dashboard.
Use environment variables to store API keys. Never hardcode them in source code.
environment
Controls console output (pretty-printing for explicit SDK methods) and the environment
label on each ingest batch. Network shipping is controlled separately by apiKey and disabled.
| Value | Console output | Ships to server (if apiKey set, disabled: false) |
|---|---|---|
development | Colored console output (default on) | Yes |
production | Off by default (consoleInProduction) | Yes |
staging | Same as production | Yes |
test | Console on | Yes |
When omitted, the SDK auto-detects in this order:
- Vite / modern bundlers —
import.meta.env.DEV,import.meta.env.MODE,import.meta.env.PROD process.env.NODE_ENV— Node and bundler define (accessed so Vite can replace it)- Local browser hosts —
localhost,127.0.0.1,[::1],*.localhost,*.local→development - Otherwise
production
Older SDK versions only checked NODE_ENV behind a typeof process guard. Under Vite
that guard often failed in the browser, so the client defaulted to production and
explicit logstack.info(...) calls shipped to the API but did not pretty-print to the
console. Upgrade to logstack-js ≥ 1.0.3, or pass environment: "development" /
consoleInProduction: true explicitly.
Console and network are decoupled. Use disabled: true for console-only
mode when you have no API key locally — you still get colored terminal output.
disabled
When true, logs are written to the console (unless silent: true) but never sent to the server. Use this for local development without an API key:
consoleInProduction
Whether to also output logs to console when in production mode.
captureContext
Automatically capture contextual information like URL, route, and user agent.
When enabled in browser environments, Logstack automatically captures:
url— Current page URLroute— URL pathnameuserAgent— Browser user agent string
captureConsole (recommended default: true)
This is the killer feature for effortless log collection.
When true (the default), Logstack automatically intercepts all native console calls:
console.log,console.info,console.debugconsole.warnconsole.errorconsole.traceconsole.assert(failed assertions are captured aserrorlevel)
The original console output always happens first, then a structured log entry with source: "console" is forwarded to Logstack (and appears in your dashboard, mobile app, and can trigger alerts).
No need to replace every console.log in your codebase. Drop the SDK in and you get comprehensive coverage immediately for both dev and prod.
To opt out (rare):
Use explicit logstack.info("msg", { rich: "metadata" }) when you want full control + structured fields. Both paths work great together.
endpoint
API endpoint URL. Use this for self-hosted instances.
| Environment | URL |
|---|---|
| Production (default) | https://api.logstack.tech |
| Self-hosted | https://logs.your-domain.com |
batchSize
Number of logs to buffer before automatically sending.
| Value | Behavior |
|---|---|
1 | Send immediately (higher latency, more requests) |
100 | Default, good balance |
500 | High-throughput applications |
flushInterval
How often to send buffered logs, in milliseconds.
Logs are sent when either batchSize is reached OR flushInterval elapses,
whichever comes first.
maxRetries
Maximum retry attempts for failed HTTP requests.
Retries use exponential backoff: 200ms → 400ms → 800ms
onError
Callback function when log submission fails after all retries.
Context Management
Set persistent context that applies to all subsequent logs:
Context Properties
| Property | Description | Example |
|---|---|---|
url | Page URL or API endpoint | '/api/users' |
route | Route path pattern | '/users/:id' |
method | HTTP method | 'POST' |
userAgent | Browser/client user agent | 'Mozilla/5.0...' |
ip | Client IP address | '192.168.1.1' |
requestId | Request tracing ID | 'req_abc123' |
component | Component or module name | 'PaymentService' |
Environment-Specific Configuration
Development
Production
Staging with Console Output
High-Throughput
Graceful Shutdown
Always handle process termination to avoid losing logs: