@@ -8,6 +8,7 @@ import { CdsProjectMapWithDebugSignals } from './src/cds/parser/types';
88import { runJavaScriptExtractor } from './src/codeql' ;
99import { addCompilationDiagnostic } from './src/diagnostics' ;
1010import { configureLgtmIndexFilters , setupAndValidateEnvironment } from './src/environment' ;
11+ import { cdsExtractorLog , setSourceRootDirectory } from './src/logging' ;
1112import { installDependencies } from './src/packageManager' ;
1213import { RunMode } from './src/runMode' ;
1314import { validateArguments } from './src/utils' ;
@@ -25,9 +26,12 @@ if (!validationResult.isValid) {
2526// Get the validated and sanitized arguments
2627const { runMode, sourceRoot } = validationResult . args ! ;
2728
29+ // Initialize the unified logging system with the source root directory
30+ setSourceRootDirectory ( sourceRoot ) ;
31+
2832// Check for autobuild mode
2933if ( runMode === ( RunMode . AUTOBUILD as string ) ) {
30- console . log ( 'Autobuild mode is not implemented yet.' ) ;
34+ cdsExtractorLog ( 'info' , 'Autobuild mode is not implemented yet.' ) ;
3135 process . exit ( 1 ) ;
3236}
3337
@@ -43,7 +47,8 @@ const {
4347
4448if ( ! envSetupSuccess ) {
4549 const codeqlExe = platformInfo . isWindows ? 'codeql.exe' : 'codeql' ;
46- console . warn (
50+ cdsExtractorLog (
51+ 'warn' ,
4752 `'${ codeqlExe } database index-files --language cds' terminated early due to: ${ errorMessages . join (
4853 ', ' ,
4954 ) } .`,
@@ -56,12 +61,13 @@ if (!envSetupSuccess) {
5661// directory as the current working directory.
5762process . chdir ( sourceRoot ) ;
5863
59- console . log (
60- `INFO: CodeQL CDS extractor using run mode '${ runMode } ' for scan of project source root directory '${ sourceRoot } '.` ,
64+ cdsExtractorLog (
65+ 'info' ,
66+ `CodeQL CDS extractor using run mode '${ runMode } ' for scan of project source root directory '${ sourceRoot } '.` ,
6167) ;
6268
6369// Using the new project-aware approach to find CDS projects and their dependencies
64- console . log ( 'Detecting CDS projects and analyzing their structure...' ) ;
70+ cdsExtractorLog ( 'info' , 'Detecting CDS projects and analyzing their structure...' ) ;
6571
6672// Build the project dependency graph using the project-aware parser
6773// Pass the script directory (__dirname) to support debug-parser mode internally
@@ -72,20 +78,23 @@ const typedProjectMap = projectMap as CdsProjectMapWithDebugSignals;
7278
7379// Check if we're in debug-parser mode and should exit (based on signals from buildCdsProjectDependencyGraph)
7480if ( typedProjectMap . __debugParserSuccess ) {
75- console . log ( 'Debug parser mode completed successfully.' ) ;
81+ cdsExtractorLog ( 'info' , 'Debug parser mode completed successfully.' ) ;
7682 process . exit ( 0 ) ;
7783} else if ( typedProjectMap . __debugParserFailure ) {
78- console . warn ( 'No CDS projects found. Cannot generate debug information.' ) ;
84+ cdsExtractorLog ( 'warn' , 'No CDS projects found. Cannot generate debug information.' ) ;
7985 process . exit ( 1 ) ;
8086}
8187
8288// Install dependencies of discovered CAP/CDS projects
83- console . log ( 'Ensuring dependencies are installed in cache for required CDS compiler versions...' ) ;
89+ cdsExtractorLog (
90+ 'info' ,
91+ 'Ensuring dependencies are installed in cache for required CDS compiler versions...' ,
92+ ) ;
8493const projectCacheDirMap = installDependencies ( projectMap , sourceRoot , codeqlExePath ) ;
8594
8695const cdsFilePathsToProcess : string [ ] = [ ] ;
8796
88- console . log ( 'Extracting CDS files from discovered projects...' ) ;
97+ cdsExtractorLog ( 'info' , 'Extracting CDS files from discovered projects...' ) ;
8998
9099// Use the project map to collect all `.cds` files from each project.
91100// We want to "extract" all `.cds` files from all projects so that we have a copy
@@ -94,7 +103,7 @@ for (const [, project] of projectMap.entries()) {
94103 cdsFilePathsToProcess . push ( ...project . cdsFiles ) ;
95104}
96105
97- console . log ( 'Processing CDS files to JSON ...' ) ;
106+ cdsExtractorLog ( 'info' , 'Processing CDS files to JSON ...' ) ;
98107
99108// Collect files that need compilation, handling project-level compilation
100109const cdsFilesToCompile : string [ ] = [ ] ;
@@ -115,7 +124,8 @@ for (const [projectDir, project] of projectMap.entries()) {
115124 }
116125}
117126
118- console . log (
127+ cdsExtractorLog (
128+ 'info' ,
119129 `Found ${ cdsFilePathsToProcess . length } total CDS files, ${ cdsFilesToCompile . length } files to compile (${ projectsForProjectLevelCompilation . size } project-level compilations)` ,
120130) ;
121131
@@ -141,14 +151,16 @@ for (const rawCdsFilePath of cdsFilesToCompile) {
141151 ) ;
142152
143153 if ( ! compilationResult . success && compilationResult . message ) {
144- console . error (
145- `ERROR: adding diagnostic for source file=${ rawCdsFilePath } : ${ compilationResult . message } ...` ,
154+ cdsExtractorLog (
155+ 'error' ,
156+ `adding diagnostic for source file=${ rawCdsFilePath } : ${ compilationResult . message } ...` ,
146157 ) ;
147158 addCompilationDiagnostic ( rawCdsFilePath , compilationResult . message , codeqlExePath ) ;
148159 }
149160 } catch ( errorMessage ) {
150- console . error (
151- `ERROR: adding diagnostic for source file=${ rawCdsFilePath } : ${ String ( errorMessage ) } ...` ,
161+ cdsExtractorLog (
162+ 'error' ,
163+ `adding diagnostic for source file=${ rawCdsFilePath } : ${ String ( errorMessage ) } ...` ,
152164 ) ;
153165 addCompilationDiagnostic ( rawCdsFilePath , String ( errorMessage ) , codeqlExePath ) ;
154166 }
@@ -160,7 +172,7 @@ configureLgtmIndexFilters();
160172// Run CodeQL's JavaScript extractor to process the compiled JSON files.
161173const extractorResult = runJavaScriptExtractor ( sourceRoot , autobuildScriptPath , codeqlExePath ) ;
162174if ( ! extractorResult . success && extractorResult . error ) {
163- console . error ( `Error running JavaScript extractor: ${ extractorResult . error } ` ) ;
175+ cdsExtractorLog ( 'error' , `Error running JavaScript extractor: ${ extractorResult . error } ` ) ;
164176}
165177
166178// Use the `cds-extractor.js` name in the log message as that is the name of the script
0 commit comments