Skip to main content
 
Field Guides

How to Send Logs from the JavaScript SDK to External Providers

Learn how to use setLogExtension to hook into the LiveKit JavaScript SDK logging system and forward logs to your preferred log provider.

Last Updated:


The LiveKit JavaScript SDK's logging includes setLogLevel and setLogExtension. The setLogExtension() function adds a hook into the SDK's logging library that is called for every log line, allowing you to forward logs to any external provider.

Usage

import { setLogExtension, LogLevel } from 'livekit-client';
setLogExtension((level, msg, context) => {
// use your log provider's API to send this log message and context
});

Examples

Basic logging with timestamp

import { setLogExtension, LogLevel } from 'livekit-client';
setLogExtension((level, msg, context) => {
const enhancedContext = { ...context, timeStamp: Date.now() };
if (level >= LogLevel.debug) {
console.log(level, msg, enhancedContext);
}
});

You can find an example in the livekit-client repository.

Adding Room-Specific Context

Use the setLogExtension function to add custom context to your room logs:

import { setLogExtension } from 'livekit-client';
setLogExtension((lvl, logmsg, ctx) => {
if ('room' in ctx) {
// Add room-specific context based on room name
ctx = { ...ctx, ...customLogContexts.get(ctx.room) };
}
// Continue forwarding with enhanced room-specific log context
});

Note: Initial connection logs won't include room context since they occur before the WebSocket connection is established. Room-specific context will be available for all subsequent logs once the room connection is established.

Available Context Information

By default, all room-level logs include:

  • Room name — The name of the connected room
  • Room ID — The unique identifier for the room

You can extend this with your own custom context information using the method shown above.