提交 637d0b2f 编写于 作者: B Benjamin Pasero

log - do not use colors on windows

上级 e9c830a5
......@@ -20,7 +20,7 @@ import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiati
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { ILogService, LegacyLogMainService, MultiplexLogService, registerGlobalLogService } from 'vs/platform/log/common/log';
import { ILogService, ConsoleLogMainService, MultiplexLogService, registerGlobalLogService } from 'vs/platform/log/common/log';
import { StateService } from 'vs/platform/state/node/stateService';
import { IStateService } from 'vs/platform/state/common/state';
import { IBackupMainService } from 'vs/platform/backup/common/backup';
......@@ -49,8 +49,8 @@ function createServices(args: ParsedArgs): IInstantiationService {
const environmentService = new EnvironmentService(args, process.execPath);
const spdlogService = new SpdLogService('main', environmentService);
const legacyLogService = new LegacyLogMainService(environmentService);
const logService = new MultiplexLogService([legacyLogService, spdlogService]);
const consoleLogService = new ConsoleLogMainService(environmentService);
const logService = new MultiplexLogService([consoleLogService, spdlogService]);
registerGlobalLogService(logService);
process.once('exit', () => logService.dispose());
......
......@@ -19,7 +19,7 @@ import { BackupMainService } from 'vs/platform/backup/electron-main/backupMainSe
import { IBackupWorkspacesFormat } from 'vs/platform/backup/common/backup';
import { HotExitConfiguration } from 'vs/platform/files/common/files';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { LegacyLogMainService } from 'vs/platform/log/common/log';
import { ConsoleLogMainService } from 'vs/platform/log/common/log';
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { createHash } from 'crypto';
import { getRandomTestPath } from 'vs/workbench/test/workbenchTestServices';
......@@ -34,7 +34,7 @@ suite('BackupMainService', () => {
class TestBackupMainService extends BackupMainService {
constructor(backupHome: string, backupWorkspacesPath: string, configService: TestConfigurationService) {
super(environmentService, configService, new LegacyLogMainService(environmentService));
super(environmentService, configService, new ConsoleLogMainService(environmentService));
this.backupHome = backupHome;
this.workspacesJsonPath = backupWorkspacesPath;
......
......@@ -9,6 +9,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { createDecorator as createServiceDecorator } from 'vs/platform/instantiation/common/instantiation';
import { createDecorator } from 'vs/base/common/decorators';
import { IDisposable } from 'vs/base/common/lifecycle';
import { isWindows } from 'vs/base/common/platform';
export const ILogService = createServiceDecorator<ILogService>('logService');
......@@ -34,13 +35,15 @@ export interface ILogService extends IDisposable {
critical(message: string | Error, ...args: any[]): void;
}
export class LegacyLogMainService implements ILogService {
export class ConsoleLogMainService implements ILogService {
_serviceBrand: any;
private level: LogLevel = LogLevel.Error;
private useColors: boolean;
constructor( @IEnvironmentService environmentService: IEnvironmentService) {
this.setLevel(environmentService.logLevel);
this.useColors = !isWindows;
}
setLevel(level: LogLevel): void {
......@@ -49,37 +52,61 @@ export class LegacyLogMainService implements ILogService {
trace(message: string, ...args: any[]): void {
if (this.level <= LogLevel.Trace) {
console.log(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
if (this.useColors) {
console.log(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
} else {
console.log(`[main ${new Date().toLocaleTimeString()}]`, message, ...args);
}
}
}
debug(message: string, ...args: any[]): void {
if (this.level <= LogLevel.Debug) {
console.log(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
if (this.useColors) {
console.log(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
} else {
console.log(`[main ${new Date().toLocaleTimeString()}]`, message, ...args);
}
}
}
info(message: string, ...args: any[]): void {
if (this.level <= LogLevel.Info) {
console.log(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
if (this.useColors) {
console.log(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
} else {
console.log(`[main ${new Date().toLocaleTimeString()}]`, message, ...args);
}
}
}
warn(message: string | Error, ...args: any[]): void {
if (this.level <= LogLevel.Warning) {
console.warn(`\x1b[93m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
if (this.useColors) {
console.warn(`\x1b[93m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
} else {
console.warn(`[main ${new Date().toLocaleTimeString()}]`, message, ...args);
}
}
}
error(message: string, ...args: any[]): void {
if (this.level <= LogLevel.Error) {
console.error(`\x1b[91m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
if (this.useColors) {
console.error(`\x1b[91m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
} else {
console.error(`[main ${new Date().toLocaleTimeString()}]`, message, ...args);
}
}
}
critical(message: string, ...args: any[]): void {
if (this.level <= LogLevel.Critical) {
console.error(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
if (this.useColors) {
console.error(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, message, ...args);
} else {
console.error(`[main ${new Date().toLocaleTimeString()}]`, message, ...args);
}
}
}
......
......@@ -15,7 +15,7 @@ import { EnvironmentService } from 'vs/platform/environment/node/environmentServ
import { parseArgs } from 'vs/platform/environment/node/argv';
import { WorkspacesMainService, IStoredWorkspace } from 'vs/platform/workspaces/electron-main/workspacesMainService';
import { WORKSPACE_EXTENSION, IWorkspaceSavedEvent, IWorkspaceIdentifier, IRawFileWorkspaceFolder, IWorkspaceFolderCreationData, IRawUriWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces';
import { LegacyLogMainService } from 'vs/platform/log/common/log';
import { ConsoleLogMainService } from 'vs/platform/log/common/log';
import URI from 'vs/base/common/uri';
import { getRandomTestPath } from 'vs/workbench/test/workbenchTestServices';
......@@ -48,7 +48,7 @@ suite('WorkspacesMainService', () => {
}
const environmentService = new TestEnvironmentService(parseArgs(process.argv), process.execPath);
const logService = new LegacyLogMainService(environmentService);
const logService = new ConsoleLogMainService(environmentService);
let service: TestWorkspacesMainService;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册