Skip to content

Commit bb937a5

Browse files
author
Benjamin Pasero
committed
log - main side 💄
1 parent 8fb1d17 commit bb937a5

4 files changed

Lines changed: 16 additions & 18 deletions

File tree

src/vs/code/electron-main/main.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ function createServices(args: ParsedArgs): IInstantiationService {
5353
const logService = new MultiplexLogService([legacyLogService, spdlogService]);
5454
registerGlobalLogService(logService);
5555

56-
logService.info('main', JSON.stringify(args));
57-
5856
// Eventually cleanup
5957
setTimeout(() => spdlogService.cleanup().then(null, err => console.error(err)), 10000);
6058

@@ -79,6 +77,7 @@ function createPaths(environmentService: IEnvironmentService): TPromise<any> {
7977
environmentService.nodeCachedDataDir,
8078
environmentService.logsPath
8179
];
80+
8281
return TPromise.join(paths.map(p => p && mkdirp(p))) as TPromise<any>;
8382
}
8483

@@ -117,7 +116,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
117116

118117
// Print --status usage info
119118
if (environmentService.args.status) {
120-
console.log('Warning: The --status argument can only be used if Code is already running. Please run it again after Code has started.');
119+
logService.warn('Warning: The --status argument can only be used if Code is already running. Please run it again after Code has started.');
121120
}
122121

123122
// Set the VSCODE_PID variable here when we are sure we are the first
@@ -236,14 +235,16 @@ function quit(accessor: ServicesAccessor, reason?: ExpectedError | Error): void
236235

237236
if (reason) {
238237
if ((reason as ExpectedError).isExpected) {
239-
logService.info(reason.message);
238+
if (reason.message) {
239+
logService.trace(reason.message);
240+
}
240241
} else {
241242
exitCode = 1; // signal error to the outside
242243

243244
if (reason.stack) {
244-
console.error(reason.stack);
245+
logService.error(reason.stack);
245246
} else {
246-
console.error(`Startup error: ${reason.toString()}`);
247+
logService.error(`Startup error: ${reason.toString()}`);
247248
}
248249
}
249250
}

src/vs/platform/state/node/stateService.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
1111
import { writeFileAndFlushSync } from 'vs/base/node/extfs';
1212
import { isUndefined, isUndefinedOrNull } from 'vs/base/common/types';
1313
import { IStateService } from 'vs/platform/state/common/state';
14+
import { ILogService } from 'vs/platform/log/common/log';
1415

1516
export class FileStorage {
1617

1718
private database: object = null;
1819

19-
constructor(private dbPath: string, private verbose?: boolean) { }
20+
constructor(private dbPath: string, private onError: (error) => void) { }
2021

2122
private ensureLoaded(): void {
2223
if (!this.database) {
@@ -68,9 +69,7 @@ export class FileStorage {
6869
try {
6970
return JSON.parse(fs.readFileSync(this.dbPath).toString()); // invalid JSON or permission issue can happen here
7071
} catch (error) {
71-
if (this.verbose) {
72-
console.error(error);
73-
}
72+
this.onError(error);
7473

7574
return {};
7675
}
@@ -80,9 +79,7 @@ export class FileStorage {
8079
try {
8180
writeFileAndFlushSync(this.dbPath, JSON.stringify(this.database, null, 4)); // permission issue can happen here
8281
} catch (error) {
83-
if (this.verbose) {
84-
console.error(error);
85-
}
82+
this.onError(error);
8683
}
8784
}
8885
}
@@ -93,8 +90,8 @@ export class StateService implements IStateService {
9390

9491
private fileStorage: FileStorage;
9592

96-
constructor( @IEnvironmentService environmentService: IEnvironmentService) {
97-
this.fileStorage = new FileStorage(path.join(environmentService.userDataPath, 'storage.json'), environmentService.verbose);
93+
constructor( @IEnvironmentService environmentService: IEnvironmentService, @ILogService logService: ILogService) {
94+
this.fileStorage = new FileStorage(path.join(environmentService.userDataPath, 'storage.json'), error => logService.error(error));
9895
}
9996

10097
public getItem<T>(key: string, defaultValue?: T): T {

src/vs/platform/state/test/node/state.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ suite('StateService', () => {
2525
return mkdirp(parentDir).then(() => {
2626
writeFileAndFlushSync(storageFile, '');
2727

28-
let service = new FileStorage(storageFile);
28+
let service = new FileStorage(storageFile, () => null);
2929

3030
service.setItem('some.key', 'some.value');
3131
assert.equal(service.getItem('some.key'), 'some.value');
@@ -37,7 +37,7 @@ suite('StateService', () => {
3737

3838
service.setItem('some.other.key', 'some.other.value');
3939

40-
service = new FileStorage(storageFile);
40+
service = new FileStorage(storageFile, () => null);
4141

4242
assert.equal(service.getItem('some.other.key'), 'some.other.value');
4343

src/vs/platform/update/electron-main/updateService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class UpdateService implements IUpdateService {
123123

124124
// Start checking for updates after 30 seconds
125125
this.scheduleCheckForUpdates(30 * 1000)
126-
.done(null, err => console.error(err));
126+
.done(null, err => this.logService.error(err));
127127
}
128128

129129
private scheduleCheckForUpdates(delay = 60 * 60 * 1000): TPromise<void> {

0 commit comments

Comments
 (0)