how to add room_name in all default livekit logs, ...
# ask-ai
b
how to add room_name in all default livekit logs, across a session
t
Thanks for reaching out, Gaurab. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Which LiveKit SDK or environment are you using for your application (for example, Python agent, JavaScript client, or another)? The steps to include
room_name
in all logs depend on this detail.
b
python
t
Hey there! Want to make your LiveKit logs more informative and easy to track? I've got a super simple trick for you. By setting up
ctx.log_context_fields
in your Python agent's entrypoint function, you can automatically include the
room_name
in every single log entry. It's like adding a helpful little tag to all your logs! Here's a quick example to show you how:
Copy code
async def entrypoint(ctx: JobContext):
    ctx.log_context_fields = {
        "room_name": ctx.room.name,
    }
    # ... rest of your code ...
Pro tip: You can totally add more fields if you want. Now all your job logs will include the
room_name
right in their JSON structure, making debugging and tracking so much easier. Pretty neat, right?
b
I added this but not logging room name
t
Hey there! Let's figure out why
room_name
isn't showing up in your logs. I know this can be frustrating, but we'll solve it together. • First, make sure you're setting
ctx.log_context_fields
in your entrypoint function after
JobContext
is initialized. Double-check that
ctx.room.name
has a valid value when you do this. • Take a look at how you're assigning the dictionary. It should look something like this:
Copy code
ctx.log_context_fields = {
    "room_name": ctx.room.name,
    "worker_id": ctx.worker_id,
}
• Pro tip: Try adding another field like
worker_id
to see if it shows up in the logs. If it does, but
room_name
doesn't, there might be an issue with
ctx.room.name
. • Do a quick scan of your code to make sure you're not accidentally overwriting the log context fields later on. • Lastly, confirm that your job is running in the right execution context and that the room connection is set up correctly. Still no luck? Let me know if other fields from
ctx.log_context_fields
are appearing, or if none of the custom fields are showing up. We'll get to the bottom of this! Sources: Job lifecycle | LiveKit Docs | livekit-agents/livekit/agents/ipc/job_proc_lazy_main.py
b
I tried adding a fixed string, but still not getting added in DEBUGlivekit.agents.pipelinespeech playout finished
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!