@codingame/monaco-vscode-log-service-override 3.2.3 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/log.js
CHANGED
|
@@ -3,7 +3,7 @@ import { SyncDescriptor } from 'vscode/vscode/vs/platform/instantiation/common/d
|
|
|
3
3
|
import { IFileService } from 'vscode/vscode/vs/platform/files/common/files';
|
|
4
4
|
import { ILoggerService, ILogService, getLogLevel } from 'vscode/vscode/vs/platform/log/common/log';
|
|
5
5
|
export { ConsoleLogger } from 'vscode/vscode/vs/platform/log/common/log';
|
|
6
|
-
import { FileLoggerService } from '
|
|
6
|
+
import { FileLoggerService } from 'vscode/vscode/vs/platform/log/common/fileLog';
|
|
7
7
|
import { LogService } from 'vscode/vscode/vs/platform/log/common/logService';
|
|
8
8
|
import { IEnvironmentService } from 'vscode/vscode/vs/platform/environment/common/environment';
|
|
9
9
|
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
@@ -14,7 +14,7 @@ import { IDefaultLogLevelsService, DefaultLogLevelsService } from 'vscode/vscode
|
|
|
14
14
|
import getServiceOverride$1 from '@codingame/monaco-vscode-environment-service-override';
|
|
15
15
|
import { logsPath } from 'vscode/workbench';
|
|
16
16
|
import { checkServicesNotInitialized } from 'vscode/lifecycle';
|
|
17
|
-
import '
|
|
17
|
+
import 'vscode/vscode/vs/workbench/contrib/logs/common/logs.contribution';
|
|
18
18
|
|
|
19
19
|
let _FileLoggerService = class _FileLoggerService extends FileLoggerService {
|
|
20
20
|
constructor(logLevel, fileService, environmentService) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-log-service-override",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "CodinGame",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"module": "index.js",
|
|
19
19
|
"types": "index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"vscode": "npm:@codingame/monaco-vscode-api@
|
|
22
|
-
"@codingame/monaco-vscode-environment-service-override": "
|
|
21
|
+
"vscode": "npm:@codingame/monaco-vscode-api@4.1.0",
|
|
22
|
+
"@codingame/monaco-vscode-environment-service-override": "4.1.0"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from '../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
-
import { ThrottledDelayer } from 'vscode/vscode/vs/base/common/async';
|
|
3
|
-
import { VSBuffer } from 'vscode/vscode/vs/base/common/buffer';
|
|
4
|
-
import { joinPath, dirname, basename } from 'vscode/vscode/vs/base/common/resources';
|
|
5
|
-
import { ByteSize, IFileService, whenProviderRegistered } from 'vscode/vscode/vs/platform/files/common/files';
|
|
6
|
-
import { BufferLogger } from 'vscode/vscode/vs/platform/log/common/bufferLog';
|
|
7
|
-
import { AbstractMessageLogger, LogLevel, AbstractLoggerService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
8
|
-
|
|
9
|
-
const MAX_FILE_SIZE = 5 * ByteSize.MB;
|
|
10
|
-
let FileLogger = class FileLogger extends AbstractMessageLogger {
|
|
11
|
-
constructor(resource, level, donotUseFormatters, fileService) {
|
|
12
|
-
super();
|
|
13
|
-
this.resource = resource;
|
|
14
|
-
this.donotUseFormatters = donotUseFormatters;
|
|
15
|
-
this.fileService = fileService;
|
|
16
|
-
this.backupIndex = 1;
|
|
17
|
-
this.buffer = '';
|
|
18
|
-
this.setLevel(level);
|
|
19
|
-
this.flushDelayer = ( new ThrottledDelayer(100 ));
|
|
20
|
-
this.initializePromise = this.initialize();
|
|
21
|
-
}
|
|
22
|
-
async flush() {
|
|
23
|
-
if (!this.buffer) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
await this.initializePromise;
|
|
27
|
-
let content = await this.loadContent();
|
|
28
|
-
if (content.length > MAX_FILE_SIZE) {
|
|
29
|
-
await this.fileService.writeFile(this.getBackupResource(), VSBuffer.fromString(content));
|
|
30
|
-
content = '';
|
|
31
|
-
}
|
|
32
|
-
if (this.buffer) {
|
|
33
|
-
content += this.buffer;
|
|
34
|
-
this.buffer = '';
|
|
35
|
-
await this.fileService.writeFile(this.resource, VSBuffer.fromString(content));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async initialize() {
|
|
39
|
-
try {
|
|
40
|
-
await this.fileService.createFile(this.resource);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
if (error.fileOperationResult !== 3 ) {
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
log(level, message) {
|
|
49
|
-
if (this.donotUseFormatters) {
|
|
50
|
-
this.buffer += message;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
this.buffer += `${this.getCurrentTimestamp()} [${this.stringifyLogLevel(level)}] ${message}\n`;
|
|
54
|
-
}
|
|
55
|
-
this.flushDelayer.trigger(() => this.flush());
|
|
56
|
-
}
|
|
57
|
-
getCurrentTimestamp() {
|
|
58
|
-
const toTwoDigits = (v) => v < 10 ? `0${v}` : v;
|
|
59
|
-
const toThreeDigits = (v) => v < 10 ? `00${v}` : v < 100 ? `0${v}` : v;
|
|
60
|
-
const currentTime = ( new Date());
|
|
61
|
-
return `${currentTime.getFullYear()}-${toTwoDigits(currentTime.getMonth() + 1)}-${toTwoDigits(currentTime.getDate())} ${toTwoDigits(currentTime.getHours())}:${toTwoDigits(currentTime.getMinutes())}:${toTwoDigits(currentTime.getSeconds())}.${toThreeDigits(currentTime.getMilliseconds())}`;
|
|
62
|
-
}
|
|
63
|
-
getBackupResource() {
|
|
64
|
-
this.backupIndex = this.backupIndex > 5 ? 1 : this.backupIndex;
|
|
65
|
-
return joinPath(dirname(this.resource), `${basename(this.resource)}_${this.backupIndex++}`);
|
|
66
|
-
}
|
|
67
|
-
async loadContent() {
|
|
68
|
-
try {
|
|
69
|
-
const content = await this.fileService.readFile(this.resource);
|
|
70
|
-
return ( content.value.toString());
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
return '';
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
stringifyLogLevel(level) {
|
|
77
|
-
switch (level) {
|
|
78
|
-
case LogLevel.Debug: return 'debug';
|
|
79
|
-
case LogLevel.Error: return 'error';
|
|
80
|
-
case LogLevel.Info: return 'info';
|
|
81
|
-
case LogLevel.Trace: return 'trace';
|
|
82
|
-
case LogLevel.Warning: return 'warning';
|
|
83
|
-
}
|
|
84
|
-
return '';
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
FileLogger = ( __decorate([
|
|
88
|
-
( __param(3, IFileService))
|
|
89
|
-
], FileLogger));
|
|
90
|
-
class FileLoggerService extends AbstractLoggerService {
|
|
91
|
-
constructor(logLevel, logsHome, fileService) {
|
|
92
|
-
super(logLevel, logsHome);
|
|
93
|
-
this.fileService = fileService;
|
|
94
|
-
}
|
|
95
|
-
doCreateLogger(resource, logLevel, options) {
|
|
96
|
-
const logger = ( new BufferLogger(logLevel));
|
|
97
|
-
whenProviderRegistered(resource, this.fileService).then(() => logger.logger = ( new FileLogger(
|
|
98
|
-
resource,
|
|
99
|
-
logger.getLevel(),
|
|
100
|
-
!!options?.donotUseFormatters,
|
|
101
|
-
this.fileService
|
|
102
|
-
)));
|
|
103
|
-
return logger;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export { FileLoggerService };
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
-
import { localize2WithPath, localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
3
|
-
import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
|
|
4
|
-
import { Categories } from 'vscode/vscode/vs/platform/action/common/actionCommonCategories';
|
|
5
|
-
import { registerAction2, Action2 } from 'vscode/vscode/vs/platform/actions/common/actions';
|
|
6
|
-
import { SetLogLevelAction } from './logsActions.js';
|
|
7
|
-
import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
|
|
8
|
-
import { whenProviderRegistered, IFileService } from 'vscode/vscode/vs/platform/files/common/files';
|
|
9
|
-
import { Extensions as Extensions$1, IOutputService } from 'vscode/vscode/vs/workbench/services/output/common/output';
|
|
10
|
-
import { Disposable, DisposableMap, DisposableStore, toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
11
|
-
import { CONTEXT_LOG_LEVEL, LogLevelToString, isLogLevel, ILogService, ILoggerService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
12
|
-
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
13
|
-
import { Event } from 'vscode/vscode/vs/base/common/event';
|
|
14
|
-
import { showWindowLogActionId, windowLogId } from 'vscode/vscode/vs/workbench/services/log/common/logConstants';
|
|
15
|
-
import { createCancelablePromise, timeout } from 'vscode/vscode/vs/base/common/async';
|
|
16
|
-
import { isCancellationError, getErrorMessage, CancellationError } from 'vscode/vscode/vs/base/common/errors';
|
|
17
|
-
import { IDefaultLogLevelsService } from 'vscode/vscode/vs/workbench/contrib/logs/common/defaultLogLevels';
|
|
18
|
-
import { ContextKeyExpr, IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
19
|
-
import { CounterSet } from 'vscode/vscode/vs/base/common/map';
|
|
20
|
-
import { IUriIdentityService } from 'vscode/vscode/vs/platform/uriIdentity/common/uriIdentity';
|
|
21
|
-
import { Schemas } from 'vscode/vscode/vs/base/common/network';
|
|
22
|
-
|
|
23
|
-
registerAction2(class extends Action2 {
|
|
24
|
-
constructor() {
|
|
25
|
-
super({
|
|
26
|
-
id: SetLogLevelAction.ID,
|
|
27
|
-
title: SetLogLevelAction.TITLE,
|
|
28
|
-
category: Categories.Developer,
|
|
29
|
-
f1: true
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
run(servicesAccessor) {
|
|
33
|
-
return servicesAccessor.get(IInstantiationService).createInstance(SetLogLevelAction, SetLogLevelAction.ID, SetLogLevelAction.TITLE.value).run();
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
registerAction2(class extends Action2 {
|
|
37
|
-
constructor() {
|
|
38
|
-
super({
|
|
39
|
-
id: 'workbench.action.setDefaultLogLevel',
|
|
40
|
-
title: ( localize2WithPath(
|
|
41
|
-
'vs/workbench/contrib/logs/common/logs.contribution',
|
|
42
|
-
'setDefaultLogLevel',
|
|
43
|
-
"Set Default Log Level"
|
|
44
|
-
)),
|
|
45
|
-
category: Categories.Developer,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
run(servicesAccessor, logLevel, extensionId) {
|
|
49
|
-
return servicesAccessor.get(IDefaultLogLevelsService).setDefaultLogLevel(logLevel, extensionId);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
let LogOutputChannels = class LogOutputChannels extends Disposable {
|
|
53
|
-
constructor(logService, loggerService, contextKeyService, fileService, uriIdentityService) {
|
|
54
|
-
super();
|
|
55
|
-
this.logService = logService;
|
|
56
|
-
this.loggerService = loggerService;
|
|
57
|
-
this.contextKeyService = contextKeyService;
|
|
58
|
-
this.fileService = fileService;
|
|
59
|
-
this.uriIdentityService = uriIdentityService;
|
|
60
|
-
this.contextKeys = ( new CounterSet());
|
|
61
|
-
this.outputChannelRegistry = ( Registry.as(Extensions$1.OutputChannels));
|
|
62
|
-
this.loggerDisposables = this._register(( new DisposableMap()));
|
|
63
|
-
const contextKey = CONTEXT_LOG_LEVEL.bindTo(contextKeyService);
|
|
64
|
-
contextKey.set(LogLevelToString(loggerService.getLogLevel()));
|
|
65
|
-
loggerService.onDidChangeLogLevel(e => {
|
|
66
|
-
if (isLogLevel(e)) {
|
|
67
|
-
contextKey.set(LogLevelToString(loggerService.getLogLevel()));
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
this.onDidAddLoggers(loggerService.getRegisteredLoggers());
|
|
71
|
-
this._register(loggerService.onDidChangeLoggers(({ added, removed }) => {
|
|
72
|
-
this.onDidAddLoggers(added);
|
|
73
|
-
this.onDidRemoveLoggers(removed);
|
|
74
|
-
}));
|
|
75
|
-
this._register(loggerService.onDidChangeVisibility(([resource, visibility]) => {
|
|
76
|
-
const logger = loggerService.getRegisteredLogger(resource);
|
|
77
|
-
if (logger) {
|
|
78
|
-
if (visibility) {
|
|
79
|
-
this.registerLogChannel(logger);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
this.deregisterLogChannel(logger);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}));
|
|
86
|
-
this.registerShowWindowLogAction();
|
|
87
|
-
this._register(Event.filter(contextKeyService.onDidChangeContext, e => e.affectsSome(this.contextKeys))(() => this.onDidChangeContext()));
|
|
88
|
-
}
|
|
89
|
-
onDidAddLoggers(loggers) {
|
|
90
|
-
for (const logger of loggers) {
|
|
91
|
-
if (logger.when) {
|
|
92
|
-
const contextKeyExpr = ContextKeyExpr.deserialize(logger.when);
|
|
93
|
-
if (contextKeyExpr) {
|
|
94
|
-
for (const key of ( contextKeyExpr.keys())) {
|
|
95
|
-
this.contextKeys.add(key);
|
|
96
|
-
}
|
|
97
|
-
if (!this.contextKeyService.contextMatchesRules(contextKeyExpr)) {
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (logger.hidden) {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
this.registerLogChannel(logger);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
onDidChangeContext() {
|
|
109
|
-
for (const logger of this.loggerService.getRegisteredLoggers()) {
|
|
110
|
-
if (logger.when) {
|
|
111
|
-
if (this.contextKeyService.contextMatchesRules(ContextKeyExpr.deserialize(logger.when))) {
|
|
112
|
-
this.registerLogChannel(logger);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
this.deregisterLogChannel(logger);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
onDidRemoveLoggers(loggers) {
|
|
121
|
-
for (const logger of loggers) {
|
|
122
|
-
if (logger.when) {
|
|
123
|
-
const contextKeyExpr = ContextKeyExpr.deserialize(logger.when);
|
|
124
|
-
if (contextKeyExpr) {
|
|
125
|
-
for (const key of ( contextKeyExpr.keys())) {
|
|
126
|
-
this.contextKeys.delete(key);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
this.deregisterLogChannel(logger);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
registerLogChannel(logger) {
|
|
134
|
-
const channel = this.outputChannelRegistry.getChannel(logger.id);
|
|
135
|
-
if (channel && this.uriIdentityService.extUri.isEqual(channel.file, logger.resource)) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const disposables = ( new DisposableStore());
|
|
139
|
-
const promise = createCancelablePromise(async (token) => {
|
|
140
|
-
await whenProviderRegistered(logger.resource, this.fileService);
|
|
141
|
-
try {
|
|
142
|
-
await this.whenFileExists(logger.resource, 1, token);
|
|
143
|
-
const existingChannel = this.outputChannelRegistry.getChannel(logger.id);
|
|
144
|
-
const remoteLogger = existingChannel?.file?.scheme === Schemas.vscodeRemote ? this.loggerService.getRegisteredLogger(existingChannel.file) : undefined;
|
|
145
|
-
if (remoteLogger) {
|
|
146
|
-
this.deregisterLogChannel(remoteLogger);
|
|
147
|
-
}
|
|
148
|
-
const hasToAppendRemote = existingChannel && logger.resource.scheme === Schemas.vscodeRemote;
|
|
149
|
-
const id = hasToAppendRemote ? `${logger.id}.remote` : logger.id;
|
|
150
|
-
const label = hasToAppendRemote ? ( localizeWithPath(
|
|
151
|
-
'vs/workbench/contrib/logs/common/logs.contribution',
|
|
152
|
-
'remote name',
|
|
153
|
-
"{0} (Remote)",
|
|
154
|
-
logger.name ?? logger.id
|
|
155
|
-
)) : logger.name ?? logger.id;
|
|
156
|
-
this.outputChannelRegistry.registerChannel({ id, label, file: logger.resource, log: true, extensionId: logger.extensionId });
|
|
157
|
-
disposables.add(toDisposable(() => this.outputChannelRegistry.removeChannel(id)));
|
|
158
|
-
if (remoteLogger) {
|
|
159
|
-
this.registerLogChannel(remoteLogger);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
if (!isCancellationError(error)) {
|
|
164
|
-
this.logService.error('Error while registering log channel', ( logger.resource.toString()), getErrorMessage(error));
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
disposables.add(toDisposable(() => promise.cancel()));
|
|
169
|
-
this.loggerDisposables.set(( logger.resource.toString()), disposables);
|
|
170
|
-
}
|
|
171
|
-
deregisterLogChannel(logger) {
|
|
172
|
-
this.loggerDisposables.deleteAndDispose(( logger.resource.toString()));
|
|
173
|
-
}
|
|
174
|
-
async whenFileExists(file, trial, token) {
|
|
175
|
-
const exists = await this.fileService.exists(file);
|
|
176
|
-
if (exists) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (token.isCancellationRequested) {
|
|
180
|
-
throw new CancellationError();
|
|
181
|
-
}
|
|
182
|
-
if (trial > 10) {
|
|
183
|
-
throw new Error(`Timed out while waiting for file to be created`);
|
|
184
|
-
}
|
|
185
|
-
this.logService.debug(`[Registering Log Channel] File does not exist. Waiting for 1s to retry.`, ( file.toString()));
|
|
186
|
-
await timeout(1000, token);
|
|
187
|
-
await this.whenFileExists(file, trial + 1, token);
|
|
188
|
-
}
|
|
189
|
-
registerShowWindowLogAction() {
|
|
190
|
-
registerAction2(class ShowWindowLogAction extends Action2 {
|
|
191
|
-
constructor() {
|
|
192
|
-
super({
|
|
193
|
-
id: showWindowLogActionId,
|
|
194
|
-
title: ( localize2WithPath(
|
|
195
|
-
'vs/workbench/contrib/logs/common/logs.contribution',
|
|
196
|
-
'show window log',
|
|
197
|
-
"Show Window Log"
|
|
198
|
-
)),
|
|
199
|
-
category: Categories.Developer,
|
|
200
|
-
f1: true
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
async run(servicesAccessor) {
|
|
204
|
-
const outputService = servicesAccessor.get(IOutputService);
|
|
205
|
-
outputService.showChannel(windowLogId);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
LogOutputChannels = ( __decorate([
|
|
211
|
-
( __param(0, ILogService)),
|
|
212
|
-
( __param(1, ILoggerService)),
|
|
213
|
-
( __param(2, IContextKeyService)),
|
|
214
|
-
( __param(3, IFileService)),
|
|
215
|
-
( __param(4, IUriIdentityService))
|
|
216
|
-
], LogOutputChannels));
|
|
217
|
-
let LogLevelMigration = class LogLevelMigration {
|
|
218
|
-
constructor(defaultLogLevelsService) {
|
|
219
|
-
defaultLogLevelsService.migrateLogLevels();
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
LogLevelMigration = ( __decorate([
|
|
223
|
-
( __param(0, IDefaultLogLevelsService))
|
|
224
|
-
], LogLevelMigration));
|
|
225
|
-
( Registry.as(Extensions.Workbench)).registerWorkbenchContribution(LogOutputChannels, 3 );
|
|
226
|
-
( Registry.as(Extensions.Workbench)).registerWorkbenchContribution(LogLevelMigration, 4 );
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
-
import { localize2WithPath, localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
3
|
-
import { Action } from 'vscode/vscode/vs/base/common/actions';
|
|
4
|
-
import { isLogLevel, LogLevel, ILoggerService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
5
|
-
import { IQuickInputService } from 'vscode/vscode/vs/platform/quickinput/common/quickInput';
|
|
6
|
-
import { URI } from 'vscode/vscode/vs/base/common/uri';
|
|
7
|
-
import { basename, dirname, isEqual } from 'vscode/vscode/vs/base/common/resources';
|
|
8
|
-
import { IOutputService } from 'vscode/vscode/vs/workbench/services/output/common/output';
|
|
9
|
-
import { telemetryLogId, extensionTelemetryLogChannelId } from 'vscode/vscode/vs/platform/telemetry/common/telemetryUtils';
|
|
10
|
-
import { IDefaultLogLevelsService } from 'vscode/vscode/vs/workbench/contrib/logs/common/defaultLogLevels';
|
|
11
|
-
import { Codicon } from 'vscode/vscode/vs/base/common/codicons';
|
|
12
|
-
import { ThemeIcon } from 'vscode/vscode/vs/base/common/themables';
|
|
13
|
-
import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
14
|
-
|
|
15
|
-
let SetLogLevelAction = class SetLogLevelAction extends Action {
|
|
16
|
-
static { this.ID = 'workbench.action.setLogLevel'; }
|
|
17
|
-
static { this.TITLE = ( localize2WithPath(
|
|
18
|
-
'vs/workbench/contrib/logs/common/logsActions',
|
|
19
|
-
'setLogLevel',
|
|
20
|
-
"Set Log Level..."
|
|
21
|
-
)); }
|
|
22
|
-
constructor(id, label, quickInputService, loggerService, outputService, defaultLogLevelsService) {
|
|
23
|
-
super(id, label);
|
|
24
|
-
this.quickInputService = quickInputService;
|
|
25
|
-
this.loggerService = loggerService;
|
|
26
|
-
this.outputService = outputService;
|
|
27
|
-
this.defaultLogLevelsService = defaultLogLevelsService;
|
|
28
|
-
}
|
|
29
|
-
async run() {
|
|
30
|
-
const logLevelOrChannel = await this.selectLogLevelOrChannel();
|
|
31
|
-
if (logLevelOrChannel !== null) {
|
|
32
|
-
if (isLogLevel(logLevelOrChannel)) {
|
|
33
|
-
this.loggerService.setLogLevel(logLevelOrChannel);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
await this.setLogLevelForChannel(logLevelOrChannel);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async selectLogLevelOrChannel() {
|
|
41
|
-
const defaultLogLevels = await this.defaultLogLevelsService.getDefaultLogLevels();
|
|
42
|
-
const extensionLogs = [], logs = [];
|
|
43
|
-
const logLevel = this.loggerService.getLogLevel();
|
|
44
|
-
for (const channel of this.outputService.getChannelDescriptors()) {
|
|
45
|
-
if (!channel.log || !channel.file || channel.id === telemetryLogId || channel.id === extensionTelemetryLogChannelId) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
const channelLogLevel = this.loggerService.getLogLevel(channel.file) ?? logLevel;
|
|
49
|
-
const item = { id: channel.id, resource: channel.file, label: channel.label, description: channelLogLevel !== logLevel ? this.getLabel(channelLogLevel) : undefined, extensionId: channel.extensionId };
|
|
50
|
-
if (channel.extensionId) {
|
|
51
|
-
extensionLogs.push(item);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
logs.push(item);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const entries = [];
|
|
58
|
-
entries.push({ type: 'separator', label: ( localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'all', "All")) });
|
|
59
|
-
entries.push(...this.getLogLevelEntries(defaultLogLevels.default, this.loggerService.getLogLevel(), true));
|
|
60
|
-
if (extensionLogs.length) {
|
|
61
|
-
entries.push({ type: 'separator', label: ( localizeWithPath(
|
|
62
|
-
'vs/workbench/contrib/logs/common/logsActions',
|
|
63
|
-
'extensionLogs',
|
|
64
|
-
"Extension Logs"
|
|
65
|
-
)) });
|
|
66
|
-
entries.push(...extensionLogs.sort((a, b) => a.label.localeCompare(b.label)));
|
|
67
|
-
}
|
|
68
|
-
entries.push({ type: 'separator', label: ( localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'loggers', "Logs")) });
|
|
69
|
-
entries.push(...logs.sort((a, b) => a.label.localeCompare(b.label)));
|
|
70
|
-
return ( new Promise((resolve, reject) => {
|
|
71
|
-
const disposables = ( new DisposableStore());
|
|
72
|
-
const quickPick = this.quickInputService.createQuickPick();
|
|
73
|
-
quickPick.placeholder = ( localizeWithPath(
|
|
74
|
-
'vs/workbench/contrib/logs/common/logsActions',
|
|
75
|
-
'selectlog',
|
|
76
|
-
"Set Log Level"
|
|
77
|
-
));
|
|
78
|
-
quickPick.items = entries;
|
|
79
|
-
let selectedItem;
|
|
80
|
-
disposables.add(quickPick.onDidTriggerItemButton(e => {
|
|
81
|
-
quickPick.hide();
|
|
82
|
-
this.defaultLogLevelsService.setDefaultLogLevel(e.item.level);
|
|
83
|
-
}));
|
|
84
|
-
disposables.add(quickPick.onDidAccept(e => {
|
|
85
|
-
selectedItem = quickPick.selectedItems[0];
|
|
86
|
-
quickPick.hide();
|
|
87
|
-
}));
|
|
88
|
-
disposables.add(quickPick.onDidHide(() => {
|
|
89
|
-
const result = selectedItem ? selectedItem.level ?? selectedItem : null;
|
|
90
|
-
disposables.dispose();
|
|
91
|
-
resolve(result);
|
|
92
|
-
}));
|
|
93
|
-
quickPick.show();
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
96
|
-
async setLogLevelForChannel(logChannel) {
|
|
97
|
-
const defaultLogLevels = await this.defaultLogLevelsService.getDefaultLogLevels();
|
|
98
|
-
const defaultLogLevel = defaultLogLevels.extensions.find(e => e[0] === logChannel.extensionId?.toLowerCase())?.[1] ?? defaultLogLevels.default;
|
|
99
|
-
const currentLogLevel = this.loggerService.getLogLevel(logChannel.resource) ?? defaultLogLevel;
|
|
100
|
-
const entries = this.getLogLevelEntries(defaultLogLevel, currentLogLevel, !!logChannel.extensionId);
|
|
101
|
-
return ( new Promise((resolve, reject) => {
|
|
102
|
-
const disposables = ( new DisposableStore());
|
|
103
|
-
const quickPick = this.quickInputService.createQuickPick();
|
|
104
|
-
quickPick.placeholder = logChannel ? ( localizeWithPath(
|
|
105
|
-
'vs/workbench/contrib/logs/common/logsActions',
|
|
106
|
-
'selectLogLevelFor',
|
|
107
|
-
" {0}: Select log level",
|
|
108
|
-
logChannel?.label
|
|
109
|
-
)) : ( localizeWithPath(
|
|
110
|
-
'vs/workbench/contrib/logs/common/logsActions',
|
|
111
|
-
'selectLogLevel',
|
|
112
|
-
"Select log level"
|
|
113
|
-
));
|
|
114
|
-
quickPick.items = entries;
|
|
115
|
-
quickPick.activeItems = entries.filter((entry) => entry.level === this.loggerService.getLogLevel());
|
|
116
|
-
let selectedItem;
|
|
117
|
-
disposables.add(quickPick.onDidTriggerItemButton(e => {
|
|
118
|
-
quickPick.hide();
|
|
119
|
-
this.defaultLogLevelsService.setDefaultLogLevel(e.item.level, logChannel.extensionId);
|
|
120
|
-
}));
|
|
121
|
-
disposables.add(quickPick.onDidAccept(e => {
|
|
122
|
-
selectedItem = quickPick.selectedItems[0];
|
|
123
|
-
quickPick.hide();
|
|
124
|
-
}));
|
|
125
|
-
disposables.add(quickPick.onDidHide(() => {
|
|
126
|
-
if (selectedItem) {
|
|
127
|
-
this.loggerService.setLogLevel(logChannel.resource, selectedItem.level);
|
|
128
|
-
}
|
|
129
|
-
disposables.dispose();
|
|
130
|
-
resolve();
|
|
131
|
-
}));
|
|
132
|
-
quickPick.show();
|
|
133
|
-
}));
|
|
134
|
-
}
|
|
135
|
-
getLogLevelEntries(defaultLogLevel, currentLogLevel, canSetDefaultLogLevel) {
|
|
136
|
-
const button = canSetDefaultLogLevel ? { iconClass: ThemeIcon.asClassName(Codicon.checkAll), tooltip: ( localizeWithPath(
|
|
137
|
-
'vs/workbench/contrib/logs/common/logsActions',
|
|
138
|
-
'resetLogLevel',
|
|
139
|
-
"Set as Default Log Level"
|
|
140
|
-
)) } : undefined;
|
|
141
|
-
return [
|
|
142
|
-
{ label: this.getLabel(LogLevel.Trace, currentLogLevel), level: LogLevel.Trace, description: this.getDescription(LogLevel.Trace, defaultLogLevel), buttons: button && defaultLogLevel !== LogLevel.Trace ? [button] : undefined },
|
|
143
|
-
{ label: this.getLabel(LogLevel.Debug, currentLogLevel), level: LogLevel.Debug, description: this.getDescription(LogLevel.Debug, defaultLogLevel), buttons: button && defaultLogLevel !== LogLevel.Debug ? [button] : undefined },
|
|
144
|
-
{ label: this.getLabel(LogLevel.Info, currentLogLevel), level: LogLevel.Info, description: this.getDescription(LogLevel.Info, defaultLogLevel), buttons: button && defaultLogLevel !== LogLevel.Info ? [button] : undefined },
|
|
145
|
-
{ label: this.getLabel(LogLevel.Warning, currentLogLevel), level: LogLevel.Warning, description: this.getDescription(LogLevel.Warning, defaultLogLevel), buttons: button && defaultLogLevel !== LogLevel.Warning ? [button] : undefined },
|
|
146
|
-
{ label: this.getLabel(LogLevel.Error, currentLogLevel), level: LogLevel.Error, description: this.getDescription(LogLevel.Error, defaultLogLevel), buttons: button && defaultLogLevel !== LogLevel.Error ? [button] : undefined },
|
|
147
|
-
{ label: this.getLabel(LogLevel.Off, currentLogLevel), level: LogLevel.Off, description: this.getDescription(LogLevel.Off, defaultLogLevel), buttons: button && defaultLogLevel !== LogLevel.Off ? [button] : undefined },
|
|
148
|
-
];
|
|
149
|
-
}
|
|
150
|
-
getLabel(level, current) {
|
|
151
|
-
let label;
|
|
152
|
-
switch (level) {
|
|
153
|
-
case LogLevel.Trace:
|
|
154
|
-
label = ( localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'trace', "Trace"));
|
|
155
|
-
break;
|
|
156
|
-
case LogLevel.Debug:
|
|
157
|
-
label = ( localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'debug', "Debug"));
|
|
158
|
-
break;
|
|
159
|
-
case LogLevel.Info:
|
|
160
|
-
label = ( localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'info', "Info"));
|
|
161
|
-
break;
|
|
162
|
-
case LogLevel.Warning:
|
|
163
|
-
label = ( localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'warn', "Warning"));
|
|
164
|
-
break;
|
|
165
|
-
case LogLevel.Error:
|
|
166
|
-
label = ( localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'err', "Error"));
|
|
167
|
-
break;
|
|
168
|
-
case LogLevel.Off:
|
|
169
|
-
label = ( localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'off', "Off"));
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
return level === current ? `$(check) ${label}` : label;
|
|
173
|
-
}
|
|
174
|
-
getDescription(level, defaultLogLevel) {
|
|
175
|
-
return defaultLogLevel === level ? ( localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'default', "Default")) : undefined;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
SetLogLevelAction = ( __decorate([
|
|
179
|
-
( __param(2, IQuickInputService)),
|
|
180
|
-
( __param(3, ILoggerService)),
|
|
181
|
-
( __param(4, IOutputService)),
|
|
182
|
-
( __param(5, IDefaultLogLevelsService))
|
|
183
|
-
], SetLogLevelAction));
|
|
184
|
-
(class OpenWindowSessionLogFileAction extends Action {
|
|
185
|
-
static { this.ID = 'workbench.action.openSessionLogFile'; }
|
|
186
|
-
static { this.TITLE = ( localize2WithPath(
|
|
187
|
-
'vs/workbench/contrib/logs/common/logsActions',
|
|
188
|
-
'openSessionLogFile',
|
|
189
|
-
"Open Window Log File (Session)..."
|
|
190
|
-
)); }
|
|
191
|
-
constructor(id, label, environmentService, fileService, quickInputService, editorService) {
|
|
192
|
-
super(id, label);
|
|
193
|
-
this.environmentService = environmentService;
|
|
194
|
-
this.fileService = fileService;
|
|
195
|
-
this.quickInputService = quickInputService;
|
|
196
|
-
this.editorService = editorService;
|
|
197
|
-
}
|
|
198
|
-
async run() {
|
|
199
|
-
const sessionResult = await this.quickInputService.pick(this.getSessions().then(sessions => ( sessions.map((s, index) => ({
|
|
200
|
-
id: ( s.toString()),
|
|
201
|
-
label: basename(s),
|
|
202
|
-
description: index === 0 ? ( localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'current', "Current")) : undefined
|
|
203
|
-
})))), {
|
|
204
|
-
canPickMany: false,
|
|
205
|
-
placeHolder: ( localizeWithPath(
|
|
206
|
-
'vs/workbench/contrib/logs/common/logsActions',
|
|
207
|
-
'sessions placeholder',
|
|
208
|
-
"Select Session"
|
|
209
|
-
))
|
|
210
|
-
});
|
|
211
|
-
if (sessionResult) {
|
|
212
|
-
const logFileResult = await this.quickInputService.pick(this.getLogFiles(( URI.parse(sessionResult.id))).then(logFiles => ( logFiles.map(s => ({
|
|
213
|
-
id: ( s.toString()),
|
|
214
|
-
label: basename(s)
|
|
215
|
-
})))), {
|
|
216
|
-
canPickMany: false,
|
|
217
|
-
placeHolder: ( localizeWithPath(
|
|
218
|
-
'vs/workbench/contrib/logs/common/logsActions',
|
|
219
|
-
'log placeholder',
|
|
220
|
-
"Select Log file"
|
|
221
|
-
))
|
|
222
|
-
});
|
|
223
|
-
if (logFileResult) {
|
|
224
|
-
return this.editorService.openEditor({ resource: ( URI.parse(logFileResult.id)), options: { pinned: true } }).then(() => undefined);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
async getSessions() {
|
|
229
|
-
const logsPath = this.environmentService.logsHome.with({ scheme: this.environmentService.logFile.scheme });
|
|
230
|
-
const result = [logsPath];
|
|
231
|
-
const stat = await this.fileService.resolve(dirname(logsPath));
|
|
232
|
-
if (stat.children) {
|
|
233
|
-
result.push(...( stat.children
|
|
234
|
-
.filter(stat => !isEqual(stat.resource, logsPath) && stat.isDirectory && /^\d{8}T\d{6}$/.test(stat.name))
|
|
235
|
-
.sort()
|
|
236
|
-
.reverse()
|
|
237
|
-
.map(d => d.resource)));
|
|
238
|
-
}
|
|
239
|
-
return result;
|
|
240
|
-
}
|
|
241
|
-
async getLogFiles(session) {
|
|
242
|
-
const stat = await this.fileService.resolve(session);
|
|
243
|
-
if (stat.children) {
|
|
244
|
-
return ( stat.children.filter(stat => !stat.isDirectory).map(stat => stat.resource));
|
|
245
|
-
}
|
|
246
|
-
return [];
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
export { SetLogLevelAction };
|