@@ -77,16 +77,16 @@ const runServer = async (args: CliArgs) => {
7777 * ```
7878 */
7979export const runApp = ( opts : ServerOptions ) => {
80+ const logLevelOption = ( defaultLevel : string ) =>
81+ new Option ( '--log-level <level>' , 'Set the logging level' )
82+ . choices ( [ 'trace' , 'debug' , 'info' , 'warn' , 'error' , 'fatal' ] )
83+ . default ( defaultLevel )
84+ . env ( 'LOG_LEVEL' ) ;
85+
8086 const program = new Command ( )
8187 . name ( 'agents' )
8288 . description ( 'LiveKit Agents CLI' )
8389 . version ( version )
84- . addOption (
85- new Option ( '--log-level <level>' , 'Set the logging level' )
86- . choices ( [ 'trace' , 'debug' , 'info' , 'warn' , 'error' , 'fatal' ] )
87- . default ( 'info' )
88- . env ( 'LOG_LEVEL' ) ,
89- )
9090 . addOption (
9191 new Option ( '--url <string>' , 'LiveKit server or Cloud project websocket URL' ) . env (
9292 'LIVEKIT_URL' ,
@@ -120,13 +120,15 @@ export const runApp = (opts: ServerOptions) => {
120120 program
121121 . command ( 'start' )
122122 . description ( 'Start the worker in production mode' )
123- . action ( ( ) => {
124- const options = program . optsWithGlobals ( ) ;
125- opts . wsURL = options . url || opts . wsURL ;
126- opts . apiKey = options . apiKey || opts . apiKey ;
127- opts . apiSecret = options . apiSecret || opts . apiSecret ;
128- opts . logLevel = options . logLevel || opts . logLevel ;
129- opts . workerToken = options . workerToken || opts . workerToken ;
123+ . addOption ( logLevelOption ( 'info' ) )
124+ . action ( ( ...[ , command ] ) => {
125+ const globalOptions = program . optsWithGlobals ( ) ;
126+ const commandOptions = command . opts ( ) ;
127+ opts . wsURL = globalOptions . url || opts . wsURL ;
128+ opts . apiKey = globalOptions . apiKey || opts . apiKey ;
129+ opts . apiSecret = globalOptions . apiSecret || opts . apiSecret ;
130+ opts . logLevel = commandOptions . logLevel ;
131+ opts . workerToken = globalOptions . workerToken || opts . workerToken ;
130132 runServer ( {
131133 opts,
132134 production : true ,
@@ -137,19 +139,14 @@ export const runApp = (opts: ServerOptions) => {
137139 program
138140 . command ( 'dev' )
139141 . description ( 'Start the worker in development mode' )
140- . addOption (
141- new Option ( '--log-level <level>' , 'Set the logging level' )
142- . choices ( [ 'trace' , 'debug' , 'info' , 'warn' , 'error' , 'fatal' ] )
143- . default ( 'debug' )
144- . env ( 'LOG_LEVEL' ) ,
145- )
142+ . addOption ( logLevelOption ( 'debug' ) )
146143 . action ( ( ...[ , command ] ) => {
147144 const globalOptions = program . optsWithGlobals ( ) ;
148145 const commandOptions = command . opts ( ) ;
149146 opts . wsURL = globalOptions . url || opts . wsURL ;
150147 opts . apiKey = globalOptions . apiKey || opts . apiKey ;
151148 opts . apiSecret = globalOptions . apiSecret || opts . apiSecret ;
152- opts . logLevel = commandOptions . logLevel || globalOptions . logLevel || opts . logLevel ;
149+ opts . logLevel = commandOptions . logLevel ;
153150 opts . workerToken = globalOptions . workerToken || opts . workerToken ;
154151 runServer ( {
155152 opts,
@@ -163,19 +160,14 @@ export const runApp = (opts: ServerOptions) => {
163160 . description ( 'Connect to a specific room' )
164161 . requiredOption ( '--room <string>' , 'Room name to connect to' )
165162 . option ( '--participant-identity <string>' , 'Identity of user to listen to' )
166- . addOption (
167- new Option ( '--log-level <level>' , 'Set the logging level' )
168- . choices ( [ 'trace' , 'debug' , 'info' , 'warn' , 'error' , 'fatal' ] )
169- . default ( 'debug' )
170- . env ( 'LOG_LEVEL' ) ,
171- )
163+ . addOption ( logLevelOption ( 'info' ) )
172164 . action ( ( ...[ , command ] ) => {
173165 const globalOptions = program . optsWithGlobals ( ) ;
174166 const commandOptions = command . opts ( ) ;
175167 opts . wsURL = globalOptions . url || opts . wsURL ;
176168 opts . apiKey = globalOptions . apiKey || opts . apiKey ;
177169 opts . apiSecret = globalOptions . apiSecret || opts . apiSecret ;
178- opts . logLevel = commandOptions . logLevel || globalOptions . logLevel || opts . logLevel ;
170+ opts . logLevel = commandOptions . logLevel ;
179171 opts . workerToken = globalOptions . workerToken || opts . workerToken ;
180172 runServer ( {
181173 opts,
@@ -189,12 +181,7 @@ export const runApp = (opts: ServerOptions) => {
189181 program
190182 . command ( 'download-files' )
191183 . description ( 'Download plugin dependency files' )
192- . addOption (
193- new Option ( '--log-level <level>' , 'Set the logging level' )
194- . choices ( [ 'trace' , 'debug' , 'info' , 'warn' , 'error' , 'fatal' ] )
195- . default ( 'debug' )
196- . env ( 'LOG_LEVEL' ) ,
197- )
184+ . addOption ( logLevelOption ( 'debug' ) )
198185 . action ( ( ...[ , command ] ) => {
199186 const commandOptions = command . opts ( ) ;
200187 initializeLogger ( { pretty : true , level : commandOptions . logLevel } ) ;
0 commit comments