Skip to content

Commit a2aa91d

Browse files
authored
change how log channels are displayed (microsoft#165935)
1 parent abc2e9d commit a2aa91d

File tree

3 files changed

+63
-42
lines changed

3 files changed

+63
-42
lines changed

src/vs/workbench/contrib/logs/common/logsActions.ts

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
1313
import { dirname, basename, isEqual } from 'vs/base/common/resources';
1414
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1515
import { IOutputChannelDescriptor, IOutputService } from 'vs/workbench/services/output/common/output';
16-
import { isUndefined } from 'vs/base/common/types';
16+
import { isNumber } from 'vs/base/common/types';
1717
import { ILogLevelService } from 'vs/workbench/contrib/logs/common/logLevelService';
1818
import { extensionTelemetryLogChannelId, telemetryLogChannelId } from 'vs/workbench/contrib/logs/common/logConstants';
1919
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
2020
import { areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
2121

22+
type LogLevelQuickPickItem = IQuickPickItem & { level: LogLevel };
23+
type LogChannelQuickPickItem = IQuickPickItem & { channel: IOutputChannelDescriptor };
24+
25+
function isLogLevel(thing: unknown): thing is LogLevel {
26+
return isNumber(thing);
27+
}
28+
2229
export class SetLogLevelAction extends Action {
2330

2431
static readonly ID = 'workbench.action.setLogLevel';
@@ -35,13 +42,17 @@ export class SetLogLevelAction extends Action {
3542
}
3643

3744
override async run(): Promise<void> {
38-
const logChannel = await this.selectLogChannel();
39-
if (!isUndefined(logChannel)) {
40-
await this.selectLogLevel(logChannel);
45+
const logLevelOrChannel = await this.selectLogLevelOrChannel();
46+
if (logLevelOrChannel !== null) {
47+
if (isLogLevel(logLevelOrChannel)) {
48+
this.logService.setLevel(logLevelOrChannel);
49+
} else {
50+
await this.setLogLevelForChannel(logLevelOrChannel);
51+
}
4152
}
4253
}
4354

44-
private async selectLogChannel(): Promise<IOutputChannelDescriptor | undefined | null> {
55+
private async selectLogLevelOrChannel(): Promise<IOutputChannelDescriptor | LogLevel | null> {
4556
const extensionLogs = [], logs = [];
4657
for (const channel of this.outputService.getChannelDescriptors()) {
4758
if (!channel.log || channel.id === telemetryLogChannelId || channel.id === extensionTelemetryLogChannelId) {
@@ -53,49 +64,68 @@ export class SetLogLevelAction extends Action {
5364
logs.push(channel);
5465
}
5566
}
56-
const entries: ({ label: string; channel?: IOutputChannelDescriptor } | IQuickPickSeparator)[] = [];
57-
entries.push({ label: nls.localize('all', "All") });
67+
const entries: (LogLevelQuickPickItem | LogChannelQuickPickItem | IQuickPickSeparator)[] = [];
68+
entries.push({ type: 'separator', label: nls.localize('all', "All") });
69+
entries.push(...this.getLogLevelEntries(this.getDefaultLogLevel(null), this.logService.getLevel()));
5870
entries.push({ type: 'separator', label: nls.localize('loggers', "Logs") });
71+
const logLevel = this.logService.getLevel();
5972
for (const channel of logs.sort((a, b) => a.label.localeCompare(b.label))) {
60-
entries.push({ label: channel.label, channel });
73+
const channelLogLevel = this.logLevelService.getLogLevel(channel.id) ?? logLevel;
74+
entries.push({ label: channel.label, channel, description: channelLogLevel !== logLevel ? this.getLabel(channelLogLevel) : undefined });
6175
}
6276
if (extensionLogs.length && logs.length) {
6377
entries.push({ type: 'separator', label: nls.localize('extensionLogs', "Extension Logs") });
6478
}
6579
for (const channel of extensionLogs.sort((a, b) => a.label.localeCompare(b.label))) {
66-
entries.push({ label: channel.label, channel });
80+
const channelLogLevel = this.logLevelService.getLogLevel(channel.id) ?? logLevel;
81+
entries.push({ label: channel.label, channel, description: channelLogLevel !== logLevel ? this.getLabel(channelLogLevel) : undefined });
82+
}
83+
const entry = await this.quickInputService.pick(entries, { placeHolder: nls.localize('selectlog', "Set Log Level") });
84+
if (entry) {
85+
if ((<LogLevelQuickPickItem>entry).level) {
86+
return (<LogLevelQuickPickItem>entry).level;
87+
}
88+
if ((<LogChannelQuickPickItem>entry).channel) {
89+
return (<LogChannelQuickPickItem>entry).channel;
90+
}
6791
}
68-
const entry = await this.quickInputService.pick(entries, { placeHolder: nls.localize('selectlog', "Select Log") });
69-
return entry ? entry.channel ?? null : undefined;
92+
return null;
7093
}
7194

72-
private async selectLogLevel(logChannel: IOutputChannelDescriptor | null): Promise<void> {
95+
private async setLogLevelForChannel(logChannel: IOutputChannelDescriptor): Promise<void> {
7396
const defaultLogLevel = this.getDefaultLogLevel(logChannel);
74-
const current = logChannel ? this.logLevelService.getLogLevel(logChannel.id) ?? defaultLogLevel : this.logService.getLevel();
75-
const entries = [
76-
{ label: this.getLabel(nls.localize('trace', "Trace"), LogLevel.Trace, current), level: LogLevel.Trace, description: this.getDescription(LogLevel.Trace, defaultLogLevel) },
77-
{ label: this.getLabel(nls.localize('debug', "Debug"), LogLevel.Debug, current), level: LogLevel.Debug, description: this.getDescription(LogLevel.Debug, defaultLogLevel) },
78-
{ label: this.getLabel(nls.localize('info', "Info"), LogLevel.Info, current), level: LogLevel.Info, description: this.getDescription(LogLevel.Info, defaultLogLevel) },
79-
{ label: this.getLabel(nls.localize('warn', "Warning"), LogLevel.Warning, current), level: LogLevel.Warning, description: this.getDescription(LogLevel.Warning, defaultLogLevel) },
80-
{ label: this.getLabel(nls.localize('err', "Error"), LogLevel.Error, current), level: LogLevel.Error, description: this.getDescription(LogLevel.Error, defaultLogLevel) },
81-
{ label: this.getLabel(nls.localize('off', "Off"), LogLevel.Off, current), level: LogLevel.Off, description: this.getDescription(LogLevel.Off, defaultLogLevel) },
82-
];
97+
const currentLogLevel = this.logLevelService.getLogLevel(logChannel.id) ?? defaultLogLevel;
98+
const entries = this.getLogLevelEntries(defaultLogLevel, currentLogLevel);
8399

84100
const entry = await this.quickInputService.pick(entries, { placeHolder: logChannel ? nls.localize('selectLogLevelFor', " {0}: Select log level", logChannel?.label) : nls.localize('selectLogLevel', "Select log level"), activeItem: entries[this.logService.getLevel()] });
85101
if (entry) {
86-
if (logChannel) {
87-
this.logLevelService.setLogLevel(logChannel.id, entry.level);
88-
} else {
89-
this.logService.setLevel(entry.level);
90-
}
102+
this.logLevelService.setLogLevel(logChannel.id, entry.level);
91103
}
92104
}
93105

94-
private getLabel(label: string, level: LogLevel, current: LogLevel): string {
95-
if (level === current) {
96-
return `$(check) ${label}`;
106+
private getLogLevelEntries(defaultLogLevel: LogLevel, currentLogLevel: LogLevel): LogLevelQuickPickItem[] {
107+
return [
108+
{ label: this.getLabel(LogLevel.Trace, currentLogLevel), level: LogLevel.Trace, description: this.getDescription(LogLevel.Trace, defaultLogLevel) },
109+
{ label: this.getLabel(LogLevel.Debug, currentLogLevel), level: LogLevel.Debug, description: this.getDescription(LogLevel.Debug, defaultLogLevel) },
110+
{ label: this.getLabel(LogLevel.Info, currentLogLevel), level: LogLevel.Info, description: this.getDescription(LogLevel.Info, defaultLogLevel) },
111+
{ label: this.getLabel(LogLevel.Warning, currentLogLevel), level: LogLevel.Warning, description: this.getDescription(LogLevel.Warning, defaultLogLevel) },
112+
{ label: this.getLabel(LogLevel.Error, currentLogLevel), level: LogLevel.Error, description: this.getDescription(LogLevel.Error, defaultLogLevel) },
113+
{ label: this.getLabel(LogLevel.Off, currentLogLevel), level: LogLevel.Off, description: this.getDescription(LogLevel.Off, defaultLogLevel) },
114+
];
115+
116+
}
117+
118+
private getLabel(level: LogLevel, current?: LogLevel): string {
119+
let label: string;
120+
switch (level) {
121+
case LogLevel.Trace: label = nls.localize('trace', "Trace"); break;
122+
case LogLevel.Debug: label = nls.localize('debug', "Debug"); break;
123+
case LogLevel.Info: label = nls.localize('info', "Info"); break;
124+
case LogLevel.Warning: label = nls.localize('warn', "Warning"); break;
125+
case LogLevel.Error: label = nls.localize('err', "Error"); break;
126+
case LogLevel.Off: label = nls.localize('off', "Off"); break;
97127
}
98-
return label;
128+
return level === current ? `$(check) ${label}` : label;
99129
}
100130

101131
private getDescription(level: LogLevel, defaultLogLevel: LogLevel): string | undefined {

src/vs/workbench/contrib/output/browser/output.contribution.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,8 @@ class OutputContribution extends Disposable implements IWorkbenchContribution {
140140
this._register(toDisposable(() => dispose(registeredChannels.values())));
141141
const registerOutputChannels = (channels: IOutputChannelDescriptor[]) => {
142142
for (const channel of channels) {
143-
let group = '0_outputchannels';
144-
let title = channel.label;
145-
if (channel.log) {
146-
title = nls.localize('logChannel', "Log ({0})", channel.label);
147-
if (channel.extensionId) {
148-
group = '2_extensionlogs';
149-
} else {
150-
group = '1_logs';
151-
}
152-
}
143+
const title = channel.label;
144+
const group = channel.extensionId ? '0_ext_outputchannels' : '1_core_outputchannels';
153145
registeredChannels.set(channel.id, registerAction2(class extends Action2 {
154146
constructor() {
155147
super({

src/vs/workbench/contrib/quickaccess/browser/viewQuickAccess.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,8 @@ export class ViewQuickAccessProvider extends PickerQuickAccessProvider<IViewQuic
203203
// Output Channels
204204
const channels = this.outputService.getChannelDescriptors();
205205
for (const channel of channels) {
206-
const label = channel.log ? localize('logChannel', "Log ({0})", channel.label) : channel.label;
207206
viewEntries.push({
208-
label,
207+
label: channel.label,
209208
containerLabel: localize('channels', "Output"),
210209
accept: () => this.outputService.showChannel(channel.id)
211210
});

0 commit comments

Comments
 (0)