Skip to content

Commit e3e4955

Browse files
kyliauayazhafiz
authored andcommitted
fix: log all console output to file
We currently ask users to submit two logs when submitting a new issue: 1. Logs from file, and 2. Logs from output channel (see screenshot below). In order to simplify the workflow, we should log all console output to file as well. This has two advantages: 1. We can piece together a more coherent picture by just looking at the log file. 2. Users no longer have to submit logs from output channel.
1 parent 0f9e82c commit e3e4955

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

server/src/session.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ const EMPTY_RANGE = lsp.Range.create(0, 0, 0, 0);
3939
export class Session {
4040
private readonly connection: lsp.IConnection;
4141
private readonly projectService: ts.server.ProjectService;
42+
private readonly logger: Logger;
4243
private diagnosticsTimeout: NodeJS.Timeout|null = null;
4344
private isProjectLoading = false;
4445

4546
constructor(options: SessionOptions) {
47+
this.logger = options.logger;
4648
// Create a connection for the server. The connection uses Node's IPC as a transport.
4749
this.connection = lsp.createConnection();
4850
this.addProtocolHandlers(this.connection);
@@ -113,6 +115,7 @@ export class Session {
113115
case ts.server.ProjectLoadingStartEvent:
114116
this.isProjectLoading = true;
115117
this.connection.sendNotification(projectLoadingNotification.start);
118+
this.logger.info(`Loading new project: ${event.data.reason}`);
116119
break;
117120
case ts.server.ProjectLoadingFinishEvent: {
118121
const {project} = event.data;
@@ -479,39 +482,34 @@ export class Session {
479482
}
480483

481484
/**
482-
* Show an error message.
485+
* Show an error message in the remote console and log to file.
483486
*
484487
* @param message The message to show.
485488
*/
486489
error(message: string): void {
487490
this.connection.console.error(message);
491+
this.logger.msg(message, ts.server.Msg.Err);
488492
}
489493

490494
/**
491-
* Show a warning message.
495+
* Show a warning message in the remote console and log to file.
492496
*
493497
* @param message The message to show.
494498
*/
495499
warn(message: string): void {
496500
this.connection.console.warn(message);
501+
// ts.server.Msg does not have warning level, so log as info.
502+
this.logger.msg(`[WARN] ${message}`, ts.server.Msg.Info);
497503
}
498504

499505
/**
500-
* Show an information message.
506+
* Show an information message in the remote console and log to file.
501507
*
502508
* @param message The message to show.
503509
*/
504510
info(message: string): void {
505511
this.connection.console.info(message);
506-
}
507-
508-
/**
509-
* Log a message.
510-
*
511-
* @param message The message to log.
512-
*/
513-
log(message: string): void {
514-
this.connection.console.log(message);
512+
this.logger.msg(message, ts.server.Msg.Info);
515513
}
516514

517515
/**

0 commit comments

Comments
 (0)