提交 594b8b8d 编写于 作者: B Benjamin Pasero

workaround #47883

上级 8c1cc70d
......@@ -300,6 +300,31 @@ export class NullLogService implements ILogService {
dispose(): void { }
}
export interface IOutputWriter {
trace(message: string): void;
debug(message: string): void;
info(message: string): void;
warn(message: string): void;
error(message: string): void;
critical(message: string): void;
setLevel(level: number): void;
clearFormatters(): void;
flush(): void;
drop(): void;
}
export class NullOutputWriter implements IOutputWriter {
trace(message: string): void { }
debug(message: string): void { }
info(message: string): void { }
warn(message: string): void { }
error(message: string): void { }
critical(message: string): void { }
setLevel(level: number): void { }
clearFormatters(): void { }
flush(): void { }
drop(): void { }
}
export function getLogLevel(environmentService: IEnvironmentService): LogLevel {
if (environmentService.verbose) {
......
......@@ -6,7 +6,7 @@
'use strict';
import * as path from 'path';
import { ILogService, LogLevel, NullLogService, AbstractLogService } from 'vs/platform/log/common/log';
import { ILogService, LogLevel, NullLogService, AbstractLogService, NullOutputWriter, IOutputWriter } from 'vs/platform/log/common/log';
import * as spdlog from 'spdlog';
export function createSpdLogService(processName: string, logLevel: LogLevel, logsFolder: string): ILogService {
......@@ -25,6 +25,16 @@ export function createSpdLogService(processName: string, logLevel: LogLevel, log
return new NullLogService();
}
export function createSpdLogOutputWriter(name: string, filename: string, filesize: number, filecount: number): IOutputWriter {
// Do not crash if spdlog rotating logger cannot be loaded (workaround for https://github.com/Microsoft/vscode/issues/47883)
try {
return new spdlog.RotatingLogger(name, filename, filesize, filecount);
} catch (e) {
console.error(e);
}
return new NullOutputWriter();
}
class SpdLogService extends AbstractLogService implements ILogService {
_serviceBrand: any;
......
......@@ -31,13 +31,13 @@ import { IFileService } from 'vs/platform/files/common/files';
import { IPanel } from 'vs/workbench/common/panel';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { RotatingLogger } from 'spdlog';
import { toLocalISOString } from 'vs/base/common/date';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { ILogService } from 'vs/platform/log/common/log';
import { ILogService, IOutputWriter } from 'vs/platform/log/common/log';
import { Schemas } from 'vs/base/common/network';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { createSpdLogOutputWriter } from 'vs/platform/log/node/spdlogService';
const OUTPUT_ACTIVE_CHANNEL_KEY = 'output.activechannel';
......@@ -201,7 +201,7 @@ abstract class AbstractFileOutputChannel extends Disposable {
*/
class OutputChannelBackedByFile extends AbstractFileOutputChannel implements OutputChannel {
private outputWriter: RotatingLogger;
private outputWriter: IOutputWriter;
private appendedMessage = '';
private loadingFromFileInProgress: boolean = false;
private resettingDelayer: ThrottledDelayer<void>;
......@@ -219,7 +219,7 @@ class OutputChannelBackedByFile extends AbstractFileOutputChannel implements Out
super({ ...outputChannelIdentifier, file: URI.file(paths.join(outputDir, `${outputChannelIdentifier.id}.log`)) }, modelUri, OUTPUT_MIME, fileService, modelService, modeService);
// Use one rotating file to check for main file reset
this.outputWriter = new RotatingLogger(this.id, this.file.fsPath, 1024 * 1024 * 30, 1);
this.outputWriter = createSpdLogOutputWriter(this.id, this.file.fsPath, 1024 * 1024 * 30, 1);
this.outputWriter.clearFormatters();
this.rotatingFilePath = `${outputChannelIdentifier.id}.1.log`;
this._register(watchOutputDirectory(paths.dirname(this.file.fsPath), logService, (eventType, file) => this.onFileChangedInOutputDirector(eventType, file)));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册