Skip to content

Commit d511fc6

Browse files
committed
Fixes logging names missing w/ minification
1 parent c1f0da3 commit d511fc6

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

src/git/models/repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export interface RepositoryFileSystemChangeEvent {
151151

152152
const instanceCounter = getScopedCounter();
153153

154-
@logName<Repository>((r, name) => `${name}(${r.id}|${r.instance})`)
154+
@logName<Repository>(r => `Repository(${r.id}|${r.instance})`)
155155
export class Repository implements Disposable {
156156
private _onDidChange = new EventEmitter<RepositoryChangeEvent>();
157157
get onDidChange(): Event<RepositoryChangeEvent> {

src/system/decorators/log.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-return */
22
import { hrtime } from '@env/hrtime';
33
import { getParameters } from '../function';
4-
import { getLoggableName, Logger } from '../logger';
4+
import { customLoggableNameFns, getLoggableName, Logger } from '../logger';
55
import { slowCallWarningThreshold } from '../logger.constants';
66
import type { LogScope } from '../logger.scope';
77
import { clearLogScope, getLoggableScopeBlock, logScopeIdGenerator, setLogScope } from '../logger.scope';
@@ -37,13 +37,8 @@ interface LogOptions<T extends (...arg: any) => any> {
3737
timed?: boolean;
3838
}
3939

40-
export const LogInstanceNameFn = Symbol('logInstanceNameFn');
41-
4240
export function logName<T>(fn: (c: T, name: string) => string) {
43-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
44-
return (target: Function): void => {
45-
(target as any)[LogInstanceNameFn] = fn;
46-
};
41+
return (target: any): void => void customLoggableNameFns.set(target, fn);
4742
}
4843

4944
export function debug<T extends (...arg: any) => any>(

src/system/logger.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { LogInstanceNameFn } from './decorators/log';
21
import type { LogLevel } from './logger.constants';
32
import type { LogScope } from './logger.scope';
43
import { padOrTruncateEnd } from './string';
@@ -317,28 +316,26 @@ function toOrderedLevel(logLevel: LogLevel): OrderedLevel {
317316
}
318317
}
319318

320-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
321-
export function getLoggableName(instance: Function | object): string {
319+
export const customLoggableNameFns = new WeakMap<object, (instance: any, name: string) => string>();
320+
321+
export function getLoggableName(instance: object): string {
322322
let ctor;
323323
if (typeof instance === 'function') {
324-
if (instance.prototype?.constructor == null) return instance.name;
325-
326-
ctor = instance.prototype.constructor;
324+
ctor = instance.prototype?.constructor;
325+
if (ctor == null) return instance.name;
327326
} else {
328327
ctor = instance.constructor;
329328
}
330329

331330
let name: string = ctor?.name ?? '';
332-
333331
// Strip webpack module name (since I never name classes with an _)
334332
const index = name.indexOf('_');
335-
name = index === -1 ? name : name.substring(index + 1);
336-
337-
if (ctor?.[LogInstanceNameFn] != null) {
338-
name = ctor[LogInstanceNameFn](instance, name);
333+
if (index !== -1) {
334+
name = name.substring(index + 1);
339335
}
340336

341-
return name;
337+
const customNameFn = customLoggableNameFns.get(ctor);
338+
return customNameFn?.(instance, name) ?? name;
342339
}
343340

344341
export interface LogProvider {

src/trackers/trackedDocument.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface TrackedGitDocumentStatus {
9696
dirtyIdle?: boolean;
9797
}
9898

99-
@logName<TrackedGitDocument>((c, name) => `${name}(${Logger.toLoggable(c.document)})`)
99+
@logName<TrackedGitDocument>(c => `TrackedGitDocument(${Logger.toLoggable(c.document)})`)
100100
export class TrackedGitDocument implements Disposable {
101101
static async create(
102102
container: Container,

src/webviews/apps/shared/ipc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function nextIpcId() {
3131

3232
type PendingHandler = (msg: IpcMessage) => void;
3333

34-
@logName<HostIpc>((c, name) => `${c.appName}(${name})`)
34+
@logName<HostIpc>(c => `${c.appName}(HostIpc)`)
3535
export class HostIpc implements Disposable {
3636
private _onReceiveMessage = new Emitter<IpcMessage>();
3737
get onReceiveMessage(): Event<IpcMessage> {

0 commit comments

Comments
 (0)