many-fall-81099
12/10/2025, 2:17 PMtall-airline-16756
12/10/2025, 2:18 PMtall-airline-16756
12/10/2025, 2:18 PMsetLogExtension() in the JavaScript SDK — this captures all SDK log messages so you can format and emit them however you need.
Example:
import { setLogExtension } from "livekit-client";
setLogExtension((level, msg, context) => {
yourJsonLogger.log({
level,
message: msg,
context,
timestamp: new Date().toISOString(),
});
});
Notes:
• This does not replace the internal logger object, but it forwards SDK log output so you can produce JSON-only logs.
• After connection, context like room name/ID is included automatically; you can add extra metadata if desired.
Would you like a version that filters levels or maps LiveKit levels to your logger's schema?
Sources: How to Send Logs from the JavaScript SDK to Providers like Datadogmany-fall-81099
12/10/2025, 2:19 PMtall-airline-16756
12/10/2025, 2:20 PMlogging (LiveKit uses the standard logging system). Steps:
1. Create a JSON formatter:
import json
import logging
class JsonFormatter(logging.Formatter):
def format(self, record):
entry = {
"timestamp": self.formatTime(record, self.datefmt),
"level": record.levelname,
"module": record.module,
"func": record.funcName,
"line": record.lineno,
"message": record.getMessage(),
}
if record.exc_info:
entry["exception"] = self.formatException(record.exc_info)
return json.dumps(entry)
1. Replace handlers for the root or LiveKit logger so SDK logs go through your formatter:
logger = logging.getLogger() # or logging.getLogger("livekit") if you want only SDK logs
logger.setLevel(logging.INFO)
# remove existing handlers
for h in logger.handlers[:]:
logger.removeHandler(h)
# add JSON handler
handler = logging.StreamHandler()
handler.setFormatter(JsonFormatter())
logger.addHandler(handler)
1. (Optional) Add contextual fields like room_name or worker_id via extra or by injecting fields where appropriate. For agent/job contexts you can also use JobContext.log_context_fields to include metadata in logs.
If you want, tell me whether you need:
• only SDK logs converted or all application logs,
• logs sent to stdout, a file, or a remote sink,
and I’ll provide the exact code snippet for that.
Sources: Log collection | LiveKit Docs | Job lifecycle | LiveKit docsmany-fall-81099
12/10/2025, 2:21 PMtall-airline-16756
12/10/2025, 2:21 PMuv run main.py dev through your JSON logger, configure Python's root logger before LiveKit initializes so every SDK logger uses your handler/formatter.
1) Add this at the very top of your entrypoint (before importing or initializing LiveKit):
import logging
import json
class JsonFormatter(logging.Formatter):
def format(self, record):
entry = {
"timestamp": self.formatTime(record, self.datefmt),
"level": record.levelname,
"module": record.module,
"func": record.funcName,
"line": record.lineno,
"message": record.getMessage(),
}
if record.exc_info:
entry["exception"] = self.formatException(record.exc_info)
return json.dumps(entry)
# Configure root logger so all libraries (including livekit) use it
root = logging.getLogger()
root.setLevel(logging.INFO) # or DEBUG
for h in root.handlers[:]:
root.removeHandler(h)
handler = logging.StreamHandler() # stdout; use FileHandler or custom handler if needed
handler.setFormatter(JsonFormatter())
root.addHandler(handler)
2) If you only want LiveKit logs routed (not all app logs), attach the handler to the LiveKit logger specifically:
lk_logger = logging.getLogger("livekit")
lk_logger.setLevel(logging.INFO)
lk_logger.handlers = []
lk_logger.addHandler(handler)
3) If you need extra context (room id, worker id), inject via extra where available or, for agent jobs, set JobContext.log_context_fields so those fields appear in logs.
Place the config at program start (before import livekit or any LiveKit client/agent start). Want a version that sends logs to a file, stdout with timestamps in ISO, or maps LiveKit levels to your schema?