Skip to content

Commit 88b60a7

Browse files
committed
Fixes logging issue
Improves getLoggableName to include @logname decorator
1 parent 5be8e11 commit 88b60a7

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

src/git/models/repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ export class Repository implements Disposable {
392392
}
393393

394394
toString(): string {
395-
return `${getLoggableName(this)}(${this.id})`;
395+
return getLoggableName(this);
396396
}
397397

398398
get virtual(): boolean {

src/system/decorators/log.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ export function log<T extends (...arg: any) => any>(options?: LogOptions<T>, deb
109109

110110
const scopeId = logScopeIdGenerator.next();
111111

112-
const instanceName =
113-
this != null
114-
? this.constructor?.[LogInstanceNameFn]?.(this, getLoggableName(this)) ?? getLoggableName(this)
115-
: undefined;
112+
const instanceName = this != null ? getLoggableName(this) : undefined;
116113

117114
let prefix = instanceName
118115
? scoped

src/system/logger.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { LogInstanceNameFn } from './decorators/log';
12
import type { LogLevel } from './logger.constants';
23
import type { LogScope } from './logger.scope';
34

@@ -272,18 +273,26 @@ function toOrderedLevel(logLevel: LogLevel): OrderedLevel {
272273
}
273274

274275
export function getLoggableName(instance: Function | object) {
275-
let name: string;
276+
let ctor;
276277
if (typeof instance === 'function') {
277278
if (instance.prototype?.constructor == null) return instance.name;
278279

279-
name = instance.prototype.constructor.name ?? '';
280+
ctor = instance.prototype.constructor;
280281
} else {
281-
name = instance.constructor?.name ?? '';
282+
ctor = instance.constructor;
282283
}
283284

285+
let name: string = ctor?.name ?? '';
286+
284287
// Strip webpack module name (since I never name classes with an _)
285288
const index = name.indexOf('_');
286-
return index === -1 ? name : name.substr(index + 1);
289+
name = index === -1 ? name : name.substr(index + 1);
290+
291+
if (ctor?.[LogInstanceNameFn] != null) {
292+
name = ctor[LogInstanceNameFn](instance, name);
293+
}
294+
295+
return name;
287296
}
288297

289298
export interface LogProvider {

src/views/nodes/abstract/viewNode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ export abstract class ViewNode<
278278
toClipboard?(type?: ClipboardType): string | Promise<string>;
279279

280280
toString(): string {
281-
const id = this.id;
282-
return `${getLoggableName(this)}${id != null ? `(${id})` : ''}`;
281+
return getLoggableName(this);
283282
}
284283

285284
protected _uri: GitUri;

src/webviews/webviewController.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { setContext } from '../system/context';
99
import { getScopedCounter } from '../system/counter';
1010
import { debug, logName } from '../system/decorators/log';
1111
import { serialize } from '../system/decorators/serialize';
12-
import { Logger } from '../system/logger';
12+
import { getLoggableName, Logger } from '../system/logger';
1313
import { getLogScope, getNewLogScope, setLogScopeExit } from '../system/logger.scope';
1414
import { isPromise } from '../system/promise';
1515
import { maybeStopWatch } from '../system/stopwatch';
@@ -512,12 +512,13 @@ export class WebviewController<
512512
): Promise<boolean> {
513513
let packed;
514514
if (notificationType.pack && params != null) {
515-
const scope = getLogScope();
516-
517-
const sw = maybeStopWatch(getNewLogScope(` serializing msg=${notificationType.method}`, scope), {
518-
log: false,
519-
logLevel: 'debug',
520-
});
515+
const sw = maybeStopWatch(
516+
getNewLogScope(`${getLoggableName(this)}.notify serializing msg=${notificationType.method}`),
517+
{
518+
log: false,
519+
logLevel: 'debug',
520+
},
521+
);
521522
packed = utf8TextEncoder.encode(JSON.stringify(params));
522523
sw?.stop();
523524
}

0 commit comments

Comments
 (0)