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

log - do not use colors on windows

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