@@ -7,13 +7,17 @@ import yargs from 'yargs/yargs';
7
7
import { disconnect } from '../../../../db/knex-database-connection.js' ;
8
8
import { learningContentCache } from '../../infrastructure/caches/learning-content-cache.js' ;
9
9
import { quitAllStorages } from '../../infrastructure/key-value-storages/index.js' ;
10
- import { logger as defaultLogger } from '../../infrastructure/utils/logger.js' ;
10
+ import { child } from '../../infrastructure/utils/logger.js' ;
11
11
12
12
function isRunningFromCli ( scriptFileUrl ) {
13
13
const modulePath = url . fileURLToPath ( scriptFileUrl ) ;
14
14
return process . argv [ 1 ] === modulePath ;
15
15
}
16
16
17
+ function loggerForScriptClass ( ScriptClass ) {
18
+ return child ( `script:${ ScriptClass . name } ` , { event : ScriptClass . name } ) ;
19
+ }
20
+
17
21
/**
18
22
* A utility class for running scripts from the command line.
19
23
*/
@@ -26,7 +30,11 @@ export class ScriptRunner {
26
30
* @param {typeof Script } ScriptClass - The script class to be instantiated and executed.
27
31
* @param {object } [dependencies] - The script runner dependencies (logger, isRunningFromCli)
28
32
*/
29
- static async execute ( scriptFileUrl , ScriptClass , dependencies = { logger : defaultLogger , isRunningFromCli } ) {
33
+ static async execute (
34
+ scriptFileUrl ,
35
+ ScriptClass ,
36
+ dependencies = { logger : loggerForScriptClass ( ScriptClass ) , isRunningFromCli } ,
37
+ ) {
30
38
const { logger, isRunningFromCli } = dependencies ;
31
39
32
40
if ( ! isRunningFromCli ( scriptFileUrl ) ) return ;
@@ -46,7 +54,7 @@ export class ScriptRunner {
46
54
47
55
if ( args . length > 0 ) logger . info ( `Arguments: ${ args . join ( ' ' ) } ` ) ;
48
56
49
- await script . run ( parsedOptions ) ;
57
+ await script . run ( parsedOptions , logger ) ;
50
58
51
59
logger . info ( `Script execution successful.` ) ;
52
60
} catch ( error ) {
0 commit comments