Skip to content

Commit 594b8b8

Browse files
author
Benjamin Pasero
committed
workaround microsoft#47883
1 parent 8c1cc70 commit 594b8b8

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/vs/platform/log/common/log.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,31 @@ export class NullLogService implements ILogService {
300300
dispose(): void { }
301301
}
302302

303+
export interface IOutputWriter {
304+
trace(message: string): void;
305+
debug(message: string): void;
306+
info(message: string): void;
307+
warn(message: string): void;
308+
error(message: string): void;
309+
critical(message: string): void;
310+
setLevel(level: number): void;
311+
clearFormatters(): void;
312+
flush(): void;
313+
drop(): void;
314+
}
315+
316+
export class NullOutputWriter implements IOutputWriter {
317+
trace(message: string): void { }
318+
debug(message: string): void { }
319+
info(message: string): void { }
320+
warn(message: string): void { }
321+
error(message: string): void { }
322+
critical(message: string): void { }
323+
setLevel(level: number): void { }
324+
clearFormatters(): void { }
325+
flush(): void { }
326+
drop(): void { }
327+
}
303328

304329
export function getLogLevel(environmentService: IEnvironmentService): LogLevel {
305330
if (environmentService.verbose) {

src/vs/platform/log/node/spdlogService.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
import * as path from 'path';
9-
import { ILogService, LogLevel, NullLogService, AbstractLogService } from 'vs/platform/log/common/log';
9+
import { ILogService, LogLevel, NullLogService, AbstractLogService, NullOutputWriter, IOutputWriter } from 'vs/platform/log/common/log';
1010
import * as spdlog from 'spdlog';
1111

1212
export function createSpdLogService(processName: string, logLevel: LogLevel, logsFolder: string): ILogService {
@@ -25,6 +25,16 @@ export function createSpdLogService(processName: string, logLevel: LogLevel, log
2525
return new NullLogService();
2626
}
2727

28+
export function createSpdLogOutputWriter(name: string, filename: string, filesize: number, filecount: number): IOutputWriter {
29+
// Do not crash if spdlog rotating logger cannot be loaded (workaround for https://github.com/Microsoft/vscode/issues/47883)
30+
try {
31+
return new spdlog.RotatingLogger(name, filename, filesize, filecount);
32+
} catch (e) {
33+
console.error(e);
34+
}
35+
return new NullOutputWriter();
36+
}
37+
2838
class SpdLogService extends AbstractLogService implements ILogService {
2939

3040
_serviceBrand: any;

src/vs/workbench/parts/output/electron-browser/outputServices.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ import { IFileService } from 'vs/platform/files/common/files';
3131
import { IPanel } from 'vs/workbench/common/panel';
3232
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
3333
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
34-
import { RotatingLogger } from 'spdlog';
3534
import { toLocalISOString } from 'vs/base/common/date';
3635
import { IWindowService } from 'vs/platform/windows/common/windows';
37-
import { ILogService } from 'vs/platform/log/common/log';
36+
import { ILogService, IOutputWriter } from 'vs/platform/log/common/log';
3837
import { Schemas } from 'vs/base/common/network';
3938
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
4039
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
40+
import { createSpdLogOutputWriter } from 'vs/platform/log/node/spdlogService';
4141

4242
const OUTPUT_ACTIVE_CHANNEL_KEY = 'output.activechannel';
4343

@@ -201,7 +201,7 @@ abstract class AbstractFileOutputChannel extends Disposable {
201201
*/
202202
class OutputChannelBackedByFile extends AbstractFileOutputChannel implements OutputChannel {
203203

204-
private outputWriter: RotatingLogger;
204+
private outputWriter: IOutputWriter;
205205
private appendedMessage = '';
206206
private loadingFromFileInProgress: boolean = false;
207207
private resettingDelayer: ThrottledDelayer<void>;
@@ -219,7 +219,7 @@ class OutputChannelBackedByFile extends AbstractFileOutputChannel implements Out
219219
super({ ...outputChannelIdentifier, file: URI.file(paths.join(outputDir, `${outputChannelIdentifier.id}.log`)) }, modelUri, OUTPUT_MIME, fileService, modelService, modeService);
220220

221221
// Use one rotating file to check for main file reset
222-
this.outputWriter = new RotatingLogger(this.id, this.file.fsPath, 1024 * 1024 * 30, 1);
222+
this.outputWriter = createSpdLogOutputWriter(this.id, this.file.fsPath, 1024 * 1024 * 30, 1);
223223
this.outputWriter.clearFormatters();
224224
this.rotatingFilePath = `${outputChannelIdentifier.id}.1.log`;
225225
this._register(watchOutputDirectory(paths.dirname(this.file.fsPath), logService, (eventType, file) => this.onFileChangedInOutputDirector(eventType, file)));

0 commit comments

Comments
 (0)