I am using nodejs javascript 1.x agent. I want to ...
# ask-ai
a
I am using nodejs javascript 1.x agent. I want to log my entries using logger and I want to change the format of agent logger. How?
t
Thanks for reaching out, Sasha. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you change the format of the agent logger in the Node.js 1.x agent! You can do this easily using the
initializeLogger
function from the LiveKit Agents SDK. This function takes a
LoggerOptions
object with two handy properties: • pretty: Set this to
true
if you'd like human-readable logs (great for development), or
false
if you prefer JSON-formatted logs (ideal for production). • level: This lets you specify the log level, such as
info
or
debug
, depending on what details you want to see. Here’s a simple example to get you started:
Copy code
import { initializeLogger } from '@livekit/agents';

// For pretty-printed logs (development)
initializeLogger({ pretty: true, level: 'info' });

// For JSON logs (production)
initializeLogger({ pretty: false, level: 'info' });
If you're looking to customize things further, like adjusting colors or adding metadata, that would involve configuring
pino-pretty
options directly. Just a heads-up, though—these advanced options aren’t exposed in the current SDK version yet. Please feel free to reach out if you want to dive deeper or need any more help—I’m here to support you every step of the way! Sources: Log collection | LiveKit Docs | Worker options | LiveKit Docs | package-lock.json | agents/src/log.ts
a
CAn I use logger to write my own info or errors
t
Absolutely! You can definitely use the logger in the Node.js 1.x agent to write your own custom info or error messages. The logger is quite flexible and supports standard logging methods like
info
,
warn
, and
error
. Plus, it lets you include structured data to give more context, which can be really helpful. Here’s a simple example to get you started:
Copy code
// Log an informational message
logger.info({ retries: 3 }, 'Recovered from text-only response');

// Log a warning message
logger.warn({ responseId: '12345' }, 'Received text-only response from API');

// Log an error message
logger.error({ errorCode: '500' }, 'An unexpected error occurred');
What’s great is that the logger works hand-in-hand with LiveKit's metrics and telemetry system. This means you can use it not just for debugging but also for monitoring and tracking custom events throughout your agent sessions. If you have any questions or need further help, feel free to ask—I’m here to help! Sources: plugins/openai/src/realtime/realtime_model.ts | Worker options | LiveKit Docs | Logs, metrics, and telemetry | LiveKit Docs
a
what package is logger in
t
I'm happy to help you with the logger in the Node.js 1.x agent! It’s part of the
@livekit/agents
package and uses the
pino
logging library behind the scenes. You’ll find it’s initialized through the
initializeLogger
function that comes with this package. To get started, just make sure the
@livekit/agents
package is installed and properly set up in your environment. From there, you can call
log()
to grab a logger instance and easily write logs at different levels like
info
,
warn
, and
error
. If you have any questions along the way, feel free to ask—I’m here to help! Sources: README.md | Logs, metrics, and telemetry | LiveKit Docs