Skip to content

Commit 7d1c899

Browse files
committed
feat: make debug logs controllable via environment variables
1 parent 49c825e commit 7d1c899

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

components/session-view.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ChatEntry } from '@/components/livekit/chat/chat-entry';
1414
import { ChatMessageView } from '@/components/livekit/chat/chat-message-view';
1515
import { MediaTiles } from '@/components/livekit/media-tiles';
1616
import useChatAndTranscription from '@/hooks/useChatAndTranscription';
17-
// import { useDebugMode } from '@/hooks/useDebug';
17+
import { useDebugMode } from '@/hooks/useDebug';
1818
import type { AppConfig } from '@/lib/types';
1919
import { cn } from '@/lib/utils';
2020

@@ -39,8 +39,9 @@ export const SessionView = ({
3939
const { messages, send } = useChatAndTranscription();
4040
const room = useRoomContext();
4141

42-
// Uncomment the below to see verbose logs showing the underlying connection lifecycle
43-
// useDebugMode();
42+
useDebugMode({
43+
enabled: process.env.NODE_END !== 'production',
44+
});
4445

4546
async function handleSendMessage(message: string) {
4647
await send(message);

hooks/useDebug.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ import * as React from 'react';
22
import { LogLevel, setLogLevel } from 'livekit-client';
33
import { useRoomContext } from '@livekit/components-react';
44

5-
export const useDebugMode = ({ logLevel }: { logLevel?: LogLevel } = {}) => {
5+
export const useDebugMode = (options: { logLevel?: LogLevel; enabled?: boolean } = {}) => {
66
const room = useRoomContext();
7+
const logLevel = options.logLevel ?? 'debug';
8+
const enabled = options.enabled ?? true;
79

810
React.useEffect(() => {
11+
if (!enabled) {
12+
setLogLevel('silent');
13+
return;
14+
}
15+
916
setLogLevel(logLevel ?? 'debug');
1017

1118
// @ts-expect-error
@@ -14,6 +21,7 @@ export const useDebugMode = ({ logLevel }: { logLevel?: LogLevel } = {}) => {
1421
return () => {
1522
// @ts-expect-error
1623
window.__lk_room = undefined;
24+
setLogLevel('silent');
1725
};
18-
}, [room, logLevel]);
26+
}, [room, enabled, logLevel]);
1927
};

0 commit comments

Comments
 (0)