@@ -15,7 +15,7 @@ import {
1515} from "../helpers" ;
1616import { ProgressCallback } from "../commandRunner" ;
1717import { QueryMetadata } from "../pure/interface-types" ;
18- import { extLogger } from "../common" ;
18+ import { extLogger , Logger , TeeLogger } from "../common" ;
1919import * as messages from "../pure/legacy-messages" ;
2020import { InitialQueryInfo , LocalQueryInfo } from "../query-results" ;
2121import * as qsClient from "./queryserver-client" ;
@@ -66,7 +66,8 @@ export class QueryInProgress {
6666 dbItem : DatabaseItem ,
6767 progress : ProgressCallback ,
6868 token : CancellationToken ,
69- queryInfo ?: LocalQueryInfo ,
69+ logger : Logger ,
70+ queryInfo : LocalQueryInfo | undefined ,
7071 ) : Promise < messages . EvaluationResult > {
7172 if ( ! dbItem . contents || dbItem . error ) {
7273 throw new Error ( "Can't run query on invalid database." ) ;
@@ -137,7 +138,7 @@ export class QueryInProgress {
137138 await this . queryEvalInfo . addQueryLogs (
138139 queryInfo ,
139140 qs . cliServer ,
140- qs . logger ,
141+ logger ,
141142 ) ;
142143 } else {
143144 void showAndLogWarningMessage (
@@ -162,6 +163,7 @@ export class QueryInProgress {
162163 program : messages . QlProgram ,
163164 progress : ProgressCallback ,
164165 token : CancellationToken ,
166+ logger : Logger ,
165167 ) : Promise < messages . CompilationMessage [ ] > {
166168 let compiled : messages . CheckQueryResult | undefined ;
167169 try {
@@ -190,16 +192,19 @@ export class QueryInProgress {
190192 target,
191193 } ;
192194
195+ // Update the active query logger every time there is a new request to compile.
196+ // This isn't ideal because in situations where there are queries running
197+ // in parallel, each query's log messages are interleaved. Fixing this
198+ // properly will require a change in the query server.
199+ qs . activeQueryLogger = logger ;
193200 compiled = await qs . sendRequest (
194201 messages . compileQuery ,
195202 params ,
196203 token ,
197204 progress ,
198205 ) ;
199206 } finally {
200- void qs . logger . log ( " - - - COMPILATION DONE - - - " , {
201- additionalLogLocation : this . queryEvalInfo . logPath ,
202- } ) ;
207+ void logger . log ( " - - - COMPILATION DONE - - - " ) ;
203208 }
204209 return ( compiled ?. messages || [ ] ) . filter (
205210 ( msg ) => msg . severity === messages . Severity . ERROR ,
@@ -386,6 +391,8 @@ export async function compileAndRunQueryAgainstDatabase(
386391 metadata ,
387392 templates ,
388393 ) ;
394+ const logger = new TeeLogger ( qs . logger , query . queryEvalInfo . logPath ) ;
395+
389396 await query . queryEvalInfo . createTimestampFile ( ) ;
390397
391398 let upgradeDir : tmp . DirectoryResult | undefined ;
@@ -402,7 +409,7 @@ export async function compileAndRunQueryAgainstDatabase(
402409 ) ;
403410 let errors ;
404411 try {
405- errors = await query . compile ( qs , qlProgram , progress , token ) ;
412+ errors = await query . compile ( qs , qlProgram , progress , token , logger ) ;
406413 } catch ( e ) {
407414 if (
408415 e instanceof ResponseError &&
@@ -422,6 +429,7 @@ export async function compileAndRunQueryAgainstDatabase(
422429 dbItem ,
423430 progress ,
424431 token ,
432+ logger ,
425433 queryInfo ,
426434 ) ;
427435 if ( result . resultType !== messages . QueryResultType . SUCCESS ) {
@@ -439,18 +447,14 @@ export async function compileAndRunQueryAgainstDatabase(
439447 result,
440448 successful : result . resultType === messages . QueryResultType . SUCCESS ,
441449 logFileLocation : result . logFileLocation ,
442- dispose : ( ) => {
443- qs . logger . removeAdditionalLogLocation ( result . logFileLocation ) ;
444- } ,
445450 } ;
446451 } else {
447452 // Error dialogs are limited in size and scrollability,
448453 // so we include a general description of the problem,
449454 // and direct the user to the output window for the detailed compilation messages.
450455 // However we don't show quick eval errors there so we need to display them anyway.
451- void qs . logger . log (
456+ void logger . log (
452457 `Failed to compile query ${ initialInfo . queryPath } against database scheme ${ qlProgram . dbschemePath } :` ,
453- { additionalLogLocation : query . queryEvalInfo . logPath } ,
454458 ) ;
455459
456460 const formattedMessages : string [ ] = [ ] ;
@@ -459,9 +463,7 @@ export async function compileAndRunQueryAgainstDatabase(
459463 const message = error . message || "[no error message available]" ;
460464 const formatted = `ERROR: ${ message } (${ error . position . fileName } :${ error . position . line } :${ error . position . column } :${ error . position . endLine } :${ error . position . endColumn } )` ;
461465 formattedMessages . push ( formatted ) ;
462- void qs . logger . log ( formatted , {
463- additionalLogLocation : query . queryEvalInfo . logPath ,
464- } ) ;
466+ void logger . log ( formatted ) ;
465467 }
466468 if ( initialInfo . isQuickEval && formattedMessages . length <= 2 ) {
467469 // If there are more than 2 error messages, they will not be displayed well in a popup
@@ -484,9 +486,8 @@ export async function compileAndRunQueryAgainstDatabase(
484486 try {
485487 await upgradeDir ?. cleanup ( ) ;
486488 } catch ( e ) {
487- void qs . logger . log (
489+ void logger . log (
488490 `Could not clean up the upgrades dir. Reason: ${ getErrorMessage ( e ) } ` ,
489- { additionalLogLocation : query . queryEvalInfo . logPath } ,
490491 ) ;
491492 }
492493 }
@@ -535,9 +536,6 @@ function createSyntheticResult(
535536 runId : 0 ,
536537 } ,
537538 successful : false ,
538- dispose : ( ) => {
539- /**/
540- } ,
541539 } ;
542540}
543541
0 commit comments