Skip to content

Commit

Permalink
fix: logger should print one timestamp for an entire group
Browse files Browse the repository at this point in the history
Logger should print a single timestamp for each "group" entry.
  • Loading branch information
kyliau authored and atscott committed Mar 15, 2021
1 parent 76e2342 commit f3930c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
7 changes: 3 additions & 4 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,8 @@ function getProbeLocations(configValue: string|null, bundled: string): string[]
/**
* Construct the arguments that's used to spawn the server process.
* @param ctx vscode extension context
* @param debug true if debug mode is on
*/
function constructArgs(ctx: vscode.ExtensionContext, debug: boolean): string[] {
function constructArgs(ctx: vscode.ExtensionContext): string[] {
const config = vscode.workspace.getConfiguration();
const args: string[] = ['--logToConsole'];

Expand All @@ -313,7 +312,7 @@ function constructArgs(ctx: vscode.ExtensionContext, debug: boolean): string[] {
// Log file does not yet exist on disk. It is up to the server to create the file.
const logFile = path.join(ctx.logPath, 'nglangsvc.log');
args.push('--logFile', logFile);
args.push('--logVerbosity', debug ? 'verbose' : ngLog);
args.push('--logVerbosity', ngLog);
}

const ngdk: string|null = config.get('angular.ngdk', null);
Expand Down Expand Up @@ -358,7 +357,7 @@ function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.Nod
// install prod bundle so we have to check whether dev bundle exists.
module: debug && fs.existsSync(devBundle) ? devBundle : prodBundle,
transport: lsp.TransportKind.ipc,
args: constructArgs(ctx, debug),
args: constructArgs(ctx),
options: {
env: debug ? devEnv : prodEnv,
execArgv: debug ? devExecArgv : prodExecArgv,
Expand Down
14 changes: 5 additions & 9 deletions server/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ class Logger implements ts.server.Logger {
}
}

static padStringRight(str: string, padding: string) {
return (str + padding).slice(0, padding.length);
}

close() {
if (this.loggingEnabled()) {
fs.close(this.fd, noop);
Expand Down Expand Up @@ -138,14 +134,14 @@ class Logger implements ts.server.Logger {
return;
}

s = `[${nowString()}] ${s}\n`;
let prefix = '';
if (!this.inGroup || this.firstInGroup) {
const prefix = Logger.padStringRight(type + ' ' + this.seq.toString(), ' ');
s = prefix + s;
this.firstInGroup = false;
prefix = `${type} ${this.seq}`.padEnd(10) + `[${nowString()}] `;
}
const entry = prefix + s + '\n';

const buf = Buffer.from(s);
fs.writeSync(this.fd, buf, 0, buf.length);
fs.writeSync(this.fd, entry);

if (!this.inGroup) {
this.seq++;
Expand Down

0 comments on commit f3930c1

Please sign in to comment.