@codingame/monaco-vscode-log-service-override 1.83.9

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.
@@ -0,0 +1,11 @@
1
+ function __decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
7
+ function __param(paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ }
10
+
11
+ export { __decorate, __param };
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default, registerAdditionalLogger } from './log.js';
2
+ export { ConsoleLogger, ILogger } from 'vscode/vscode/vs/platform/log/common/log';
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default, registerAdditionalLogger } from './log.js';
2
+ export { ConsoleLogger } from 'monaco-editor/esm/vs/platform/log/common/log.js';
package/log.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { IEditorOverrideServices } from 'vscode/vscode/vs/editor/standalone/browser/standaloneServices';
2
+ import { LogLevel, ILogger } from 'vscode/vscode/vs/platform/log/common/log';
3
+ export { ConsoleLogger, ILogger } from 'vscode/vscode/vs/platform/log/common/log';
4
+ import { IDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
5
+
6
+ declare function getServiceOverride(): IEditorOverrideServices;
7
+ /**
8
+ * @deprecated Provide logLevel via the services `initialize` function `configuration.developmentOptions.logLevel` parameter
9
+ */
10
+ declare function getServiceOverride(logLevel?: LogLevel): IEditorOverrideServices;
11
+
12
+ declare function registerAdditionalLogger(logger: ILogger): IDisposable;
13
+
14
+ export { getServiceOverride as default, registerAdditionalLogger };
package/log.js ADDED
@@ -0,0 +1,56 @@
1
+ import { __decorate, __param } from './external/tslib/tslib.es6.js';
2
+ import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/common/descriptors.js';
3
+ import { IFileService } from 'monaco-editor/esm/vs/platform/files/common/files.js';
4
+ import { ILoggerService, ILogService, getLogLevel } from 'monaco-editor/esm/vs/platform/log/common/log.js';
5
+ export { ConsoleLogger } from 'monaco-editor/esm/vs/platform/log/common/log.js';
6
+ import { FileLoggerService } from './vscode/src/vs/platform/log/common/fileLog.js';
7
+ import { LogService } from 'monaco-editor/esm/vs/platform/log/common/logService.js';
8
+ import { IEnvironmentService } from 'monaco-editor/esm/vs/platform/environment/common/environment.js';
9
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
10
+ import { windowLogId } from 'vscode/vscode/vs/workbench/services/log/common/logConstants';
11
+ import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService';
12
+ import { toDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
13
+ import getServiceOverride$1 from '@codingame/monaco-vscode-environment-service-override';
14
+ import { logsPath } from 'vscode/workbench';
15
+ import './vscode/src/vs/workbench/contrib/logs/common/logs.contribution.js';
16
+ import { checkServicesNotInitialized } from 'vscode/lifecycle';
17
+
18
+ let _FileLoggerService = class _FileLoggerService extends FileLoggerService {
19
+ constructor(logLevel, fileService, environmentService) {
20
+ super(logLevel ?? getLogLevel(environmentService), logsPath, fileService);
21
+ }
22
+ };
23
+ _FileLoggerService = __decorate([
24
+ ( __param(1, IFileService)),
25
+ ( __param(2, IEnvironmentService))
26
+ ], _FileLoggerService);
27
+ const otherLoggers = [];
28
+ let _LogService = class _LogService extends LogService {
29
+ constructor(loggerService, environmentService) {
30
+ const logger = loggerService.createLogger(environmentService.logFile, { id: windowLogId, name: ( localizeWithPath('vs/workbench/browser/web.main', 'rendererLog', 'Window')) });
31
+ super(logger, otherLoggers);
32
+ }
33
+ };
34
+ _LogService = __decorate([
35
+ ( __param(0, ILoggerService)),
36
+ ( __param(1, IWorkbenchEnvironmentService))
37
+ ], _LogService);
38
+ function getServiceOverride(logLevel) {
39
+ return {
40
+ ...getServiceOverride$1(),
41
+ [( ILoggerService.toString())]: new SyncDescriptor(_FileLoggerService, [logLevel], true),
42
+ [( ILogService.toString())]: new SyncDescriptor(_LogService, [], true)
43
+ };
44
+ }
45
+ function registerAdditionalLogger(logger) {
46
+ checkServicesNotInitialized();
47
+ otherLoggers.push(logger);
48
+ return toDisposable(() => {
49
+ const idx = otherLoggers.indexOf(logger);
50
+ if (idx >= 0) {
51
+ otherLoggers.splice(idx, 1);
52
+ }
53
+ });
54
+ }
55
+
56
+ export { getServiceOverride as default, registerAdditionalLogger };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@codingame/monaco-vscode-log-service-override",
3
+ "version": "1.83.9",
4
+ "keywords": [],
5
+ "author": {
6
+ "name": "CodinGame",
7
+ "url": "http://www.codingame.com"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/CodinGame/monaco-vscode-api.git"
13
+ },
14
+ "type": "module",
15
+ "private": false,
16
+ "description": "VSCode public API plugged on the monaco editor - log service-override",
17
+ "main": "index.js",
18
+ "module": "index.js",
19
+ "types": "index.d.ts",
20
+ "dependencies": {
21
+ "vscode": "npm:@codingame/monaco-vscode-api@1.83.9",
22
+ "monaco-editor": "0.44.0",
23
+ "@codingame/monaco-vscode-environment-service-override": "1.83.9"
24
+ }
25
+ }
@@ -0,0 +1,107 @@
1
+ import { __decorate, __param } from '../../../../../../external/tslib/tslib.es6.js';
2
+ import { ThrottledDelayer } from 'monaco-editor/esm/vs/base/common/async.js';
3
+ import { VSBuffer } from 'monaco-editor/esm/vs/base/common/buffer.js';
4
+ import { joinPath, dirname, basename } from 'monaco-editor/esm/vs/base/common/resources.js';
5
+ import { ByteSize, IFileService, whenProviderRegistered } from 'monaco-editor/esm/vs/platform/files/common/files.js';
6
+ import { BufferLogger } from 'vscode/vscode/vs/platform/log/common/bufferLog';
7
+ import { AbstractMessageLogger, LogLevel, AbstractLoggerService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
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 };
@@ -0,0 +1,5 @@
1
+ import { createDecorator } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
2
+
3
+ const IDefaultLogLevelsService = ( createDecorator('IDefaultLogLevelsService'));
4
+
5
+ export { IDefaultLogLevelsService };
@@ -0,0 +1,217 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import * as nls from 'monaco-editor/esm/vs/nls.js';
3
+ import { Registry } from 'monaco-editor/esm/vs/platform/registry/common/platform.js';
4
+ import { Categories } from 'monaco-editor/esm/vs/platform/action/common/actionCommonCategories.js';
5
+ import { registerAction2, Action2 } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
6
+ import { SetLogLevelAction } from './logsActions.js';
7
+ import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
8
+ import { whenProviderRegistered, IFileService } from 'monaco-editor/esm/vs/platform/files/common/files.js';
9
+ import { Extensions as Extensions$1, IOutputService } from 'vscode/vscode/vs/workbench/services/output/common/output';
10
+ import { Disposable, DisposableMap, DisposableStore, toDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
11
+ import { CONTEXT_LOG_LEVEL, LogLevelToString, isLogLevel, ILogService, ILoggerService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
12
+ import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
13
+ import { Event } from 'monaco-editor/esm/vs/base/common/event.js';
14
+ import { showWindowLogActionId, windowLogId } from 'vscode/vscode/vs/workbench/services/log/common/logConstants';
15
+ import { createCancelablePromise, timeout } from 'monaco-editor/esm/vs/base/common/async.js';
16
+ import { isCancellationError, getErrorMessage, CancellationError } from 'monaco-editor/esm/vs/base/common/errors.js';
17
+ import { IDefaultLogLevelsService } from './defaultLogLevels.js';
18
+ import { ContextKeyExpr, IContextKeyService } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey.js';
19
+ import { CounterSet } from 'monaco-editor/esm/vs/base/common/map.js';
20
+ import { IUriIdentityService } from 'monaco-editor/esm/vs/platform/uriIdentity/common/uriIdentity.js';
21
+ import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
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: { value: ( nls.localizeWithPath(
41
+ 'vs/workbench/contrib/logs/common/logs.contribution',
42
+ 'setDefaultLogLevel',
43
+ "Set Default Log Level"
44
+ )), original: 'Set Default Log Level' },
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 ? ( nls.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: { value: ( nls.localizeWithPath(
195
+ 'vs/workbench/contrib/logs/common/logs.contribution',
196
+ 'show window log',
197
+ "Show Window Log"
198
+ )), original: 'Show Window Log' },
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
+ ( Registry.as(Extensions.Workbench)).registerWorkbenchContribution(LogOutputChannels, 3 );
@@ -0,0 +1,250 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import * as nls from 'monaco-editor/esm/vs/nls.js';
3
+ import { Action } from 'monaco-editor/esm/vs/base/common/actions.js';
4
+ import { isLogLevel, LogLevel, ILoggerService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
5
+ import { IQuickInputService } from 'monaco-editor/esm/vs/platform/quickinput/common/quickInput.js';
6
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
7
+ import { basename, dirname, isEqual } from 'monaco-editor/esm/vs/base/common/resources.js';
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 './defaultLogLevels.js';
11
+ import { Codicon } from 'monaco-editor/esm/vs/base/common/codicons.js';
12
+ import { ThemeIcon } from 'monaco-editor/esm/vs/base/common/themables.js';
13
+ import { DisposableStore } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
14
+
15
+ let SetLogLevelAction = class SetLogLevelAction extends Action {
16
+ static { this.ID = 'workbench.action.setLogLevel'; }
17
+ static { this.TITLE = { value: ( nls.localizeWithPath(
18
+ 'vs/workbench/contrib/logs/common/logsActions',
19
+ 'setLogLevel',
20
+ "Set Log Level..."
21
+ )), original: 'Set Log Level...' }; }
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: ( nls.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: ( nls.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: ( nls.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 = ( nls.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 ? ( nls.localizeWithPath(
105
+ 'vs/workbench/contrib/logs/common/logsActions',
106
+ 'selectLogLevelFor',
107
+ " {0}: Select log level",
108
+ logChannel?.label
109
+ )) : ( nls.localizeWithPath(
110
+ 'vs/workbench/contrib/logs/common/logsActions',
111
+ 'selectLogLevel',
112
+ "Select log level"
113
+ ));
114
+ quickPick.items = entries;
115
+ quickPick.activeItems = [entries[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: ( nls.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 = ( nls.localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'trace', "Trace"));
155
+ break;
156
+ case LogLevel.Debug:
157
+ label = ( nls.localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'debug', "Debug"));
158
+ break;
159
+ case LogLevel.Info:
160
+ label = ( nls.localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'info', "Info"));
161
+ break;
162
+ case LogLevel.Warning:
163
+ label = ( nls.localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'warn', "Warning"));
164
+ break;
165
+ case LogLevel.Error:
166
+ label = ( nls.localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'err', "Error"));
167
+ break;
168
+ case LogLevel.Off:
169
+ label = ( nls.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 ? ( nls.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 = { value: ( nls.localizeWithPath(
187
+ 'vs/workbench/contrib/logs/common/logsActions',
188
+ 'openSessionLogFile',
189
+ "Open Window Log File (Session)..."
190
+ )), original: 'Open Window Log File (Session)...' }; }
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 ? ( nls.localizeWithPath('vs/workbench/contrib/logs/common/logsActions', 'current', "Current")) : undefined
203
+ })))), {
204
+ canPickMany: false,
205
+ placeHolder: ( nls.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: ( nls.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 };