Logger (@video/log-client)
Turn on, filter and read client-side logs.
@video/log-client is the standalone browser logger package. It shares its Level names and writer options with the core client's built-in logger, but it is a separate writer: the core client does not route its own entries through it. Most integrators never import it: you enable the core client's logging by passing loggerConfig, which sets the same host and level options this package exposes. This page covers that path first, then the package's own API for code that runs outside the core client.
Install
The core client bundles its own writer (@video/ecs-log-client, which uses the same levels), so you install @video/log-client yourself only for direct use. It is published on the same private registry as the other SDK packages.
yarn add @video/log-client
npm install @video/log-client
Enable logging with loggerConfig
Pass loggerConfig when you construct the core client. clientName is the only required field; with nothing else set, output is console-only.
import { VideoClient } from "@video/video-client-core";
const client = new VideoClient({
userId: "user-123",
loggerConfig: { clientName: "my-app" },
});
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
clientName | string | yes | none | Required by the options schema. The current core client validates it and does not forward it to the writer or attach it to entries. |
host | string (URL) | no | none | Log endpoint that receives batched entries. When you omit it, logs are console-only: nothing is shipped to the network. |
level | Level | no | warn | Minimum level shipped to host. One of the 11 names in Levels. Has no effect on console output. |
writeLevel | Level | no | none | Deprecated alias of level. When both are set, level wins. Use level in new code. |
The core client forwards host and level to its built-in writer's setOptions and leaves every other writer option at its default. That writer is not LoggerGlobal: calling LoggerGlobal.setOptions from @video/log-client changes nothing about where the core client's entries go.
Levels
Level has 11 names, declared in LEVELS in this order: trace, debug, network, timing, local, info, warn, notice, deprecated, error, fatal. The names are not a rank order. The writer collapses them into four priority tiers, and a log entry ships when its tier is at or below the tier of the configured level.
| Tier | Levels | Ships when level is |
|---|---|---|
| 0 | fatal, error | any level |
| 1 | warn, notice, deprecated | tier 1 or higher: warn, notice, deprecated, info, local, debug, timing, network, trace |
| 2 | info | tier 2 or higher: info, local, debug, timing, network, trace |
| 3 | local, debug, timing, network, trace | tier 3: local, debug, timing, network, trace |
Two consequences of the tiers:
- Levels in one tier are equivalent as a threshold.
level: "debug"also shipstrace,network,timingandlocal;level: "trace"behaves the same aslevel: "debug". - When you omit
level, the writer defaults towarn, so a client with ahostand nolevelships tiers 0 and 1 only.
The example below ships warn, notice, deprecated, error and fatal to the endpoint; info and the tier 3 levels stay in the console.
import { VideoClient } from "@video/video-client-core";
const client = new VideoClient({
userId: "user-123",
loggerConfig: {
clientName: "my-app",
host: "https://logs.example.com",
level: "warn",
},
});
level is typed as Level, so a value outside the 11 names is a TypeScript error. loggerConfig: { clientName: "my-app", level: "verbose" } does not compile. Valid values: trace, debug, network, timing, local, info, warn, notice, deprecated, error, fatal.
Reading output
Every log entry goes to the browser console. Entries that meet level also go to host when you set one.
Console
The console receives every level, regardless of host and level. What each line looks like depends on which writer produced it:
- Entries from the core client are printed by its built-in writer as one JSON document per entry, in the same shape that
hostreceives.warnanderrorgo throughconsole.warnandconsole.error; every other level goes throughconsole.log. SetlocalStorage["ecs-log-client:console"] = "false"in devtools to silence them. - Entries from a
LoggerCoreyou create with@video/log-clientshow the aggregate chain (when one is set) followed by the message, styled with a per-level colour, with the structured data object after it.warnanderrorgo throughconsole.warnandconsole.error; every other level goes through thedebugpackage under the name you pass toLoggerCore, hidden until you enable that namespace, for example withlocalStorage.debug = "*"in devtools and a reload.
Host endpoint
When host is set, the writer buffers entries that meet level and POSTs them to that URL in batches:
- A batch is sent every
intervalmilliseconds (default30000) and holds up tolimitentries (default500). maxRequestSizecaps the request body in bytes (default1048576, 1 MiB).errorandfatalentries trigger an early, throttled send.
For loggers created from @video/log-client, you can tune these writer options on LoggerGlobal. The core client's built-in writer exposes only host and level through loggerConfig; its batch timing is not configurable from the client options.
import { LoggerGlobal } from "@video/log-client";
LoggerGlobal.setOptions({
host: "https://logs.example.com",
level: "debug",
interval: 5_000, // milliseconds
});
Direct use
Use the package directly for code that runs outside the core client, such as your own components or a companion library. LoggerCore is the per-package logger; LoggerGlobal is the shared writer that every LoggerCore instance registers with.
import { LoggerCore, LoggerGlobal } from "@video/log-client";
const log = new LoggerCore("my-component");
const callId = "call-42";
log.log("info", "joined", { callId });
log.warn("reconnecting", { attempt: 2 });
log.throttledLog("warn", 1000, "high packet loss", { callId, loss: 0.2 });
log.flush();
const writer = new LoggerGlobal();
writer.setOptions({ level: "info" });
| Member | Description |
|---|---|
LoggerGlobal.setOptions(options) | Static. Applies a Partial<WriterOptions> (host, level, interval, limit, maxRequestSize) to the shared writer. |
new LoggerGlobal().setOptions(options) | Instance form of the same call. |
new LoggerCore(name) | Creates a logger. name becomes the package name on every entry and the debug namespace in the console. |
log.log(level, message, data?) | Writes one entry at level. data is an object of structured fields attached to the entry. |
log.info(message, data?) and the other 10 level methods | Shorthand for log.log("info", ...). One method per name in LEVELS. |
log.throttledLog(level, ms, message, data) | Writes at most once per ms for the same message. |
log.flush() | Sends the buffered batch now instead of waiting for interval. |
log.destroy() | Detaches the logger from the shared writer. |
Scope
@video/log-node (the server-side logger and the log endpoint) is not covered by this page. It appears here only because @video/log-client re-exports the Level type and the LEVELS array from it. @video/ecs-log-client, the core client's built-in writer, is covered only as far as loggerConfig reaches it.
See also
- Errors & Logging: the generated core reference for
VideoClientError,ErrorCodeand theLoggerinterface the core client exposes. - Error Handling: symptom-first troubleshooting for the core client.