Skip to content

Commit 2caff70

Browse files
committed
Internal Rework of how the logging is called
1 parent c0f5e7a commit 2caff70

File tree

7 files changed

+31
-26
lines changed

7 files changed

+31
-26
lines changed

src/git/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class GitFile {
2525
);
2626

2727
if (!isOpen) {
28-
ErrorHandler.getInstance().logInfo(
28+
ErrorHandler.logInfo(
2929
`Clearing the file "${
3030
this.fileName.fsPath
3131
}" from the internal cache`,

src/git/filedummy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class GitFileDummy extends GitFile {
55
constructor(fileName: string, disposeCallback: () => void) {
66
super(fileName, disposeCallback);
77
this.startCacheInterval();
8-
ErrorHandler.getInstance().logInfo(
8+
ErrorHandler.logInfo(
99
`Will not try to blame file "${
1010
this.fileName.fsPath
1111
}" as it is outside of the current workspace`,

src/git/filephysical.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class GitFilePhysical extends GitFile {
140140
} else {
141141
StatusBarView.getInstance().stopProgress();
142142
this.startCacheInterval();
143-
ErrorHandler.getInstance().logInfo(
143+
ErrorHandler.logInfo(
144144
`File "${
145145
this.fileName.fsPath
146146
}" is not a decendant of a git repository`,
@@ -179,10 +179,10 @@ export class GitFilePhysical extends GitFile {
179179
this.startCacheInterval();
180180

181181
if (err) {
182-
ErrorHandler.getInstance().logError(err);
182+
ErrorHandler.logError(err);
183183
resolve(GitBlame.blankBlameInfo());
184184
} else {
185-
ErrorHandler.getInstance().logInfo(
185+
ErrorHandler.logInfo(
186186
`Blamed file "${this.fileName.fsPath}" and found ${
187187
Object.keys(blameInfo.commits).length
188188
} commits`,

src/git/stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class GitBlameStream extends EventEmitter {
2929
cwd: workTree,
3030
};
3131

32-
ErrorHandler.getInstance().logCommand(
32+
ErrorHandler.logCommand(
3333
`${gitCommand} ${args.join(" ")}`,
3434
);
3535

src/util/errorhandler.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@ enum LogCategory {
1111
}
1212

1313
export class ErrorHandler {
14+
public static logInfo(message: string) {
15+
ErrorHandler.getInstance().writeToLog(LogCategory.Info, message);
16+
}
17+
18+
public static logCommand(message: string): void {
19+
ErrorHandler.getInstance().writeToLog(LogCategory.Command, message);
20+
}
21+
22+
public static logError(error: Error): void {
23+
ErrorHandler.getInstance().writeToLog(
24+
LogCategory.Error,
25+
error.toString(),
26+
);
27+
}
28+
29+
public static logCritical(error: Error, message: string): void {
30+
ErrorHandler.getInstance().writeToLog(
31+
LogCategory.Critical,
32+
error.toString(),
33+
);
34+
ErrorHandler.getInstance().showErrorMessage(message);
35+
}
1436

1537
public static getInstance(): ErrorHandler {
1638
if (!ErrorHandler.instance) {
@@ -46,23 +68,6 @@ export class ErrorHandler {
4668
this.outputChannel = window.createOutputChannel("Extension: gitblame");
4769
}
4870

49-
public logInfo(message: string) {
50-
this.writeToLog(LogCategory.Info, message);
51-
}
52-
53-
public logCommand(message: string): void {
54-
this.writeToLog(LogCategory.Command, message);
55-
}
56-
57-
public logError(error: Error): void {
58-
this.writeToLog(LogCategory.Error, error.toString());
59-
}
60-
61-
public logCritical(error: Error, message: string): void {
62-
this.writeToLog(LogCategory.Critical, error.toString());
63-
this.showErrorMessage(message);
64-
}
65-
6671
public dispose() {
6772
this.outputChannel.dispose();
6873
}

src/util/execcommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ export function execute(
88
options: ExecOptions = {},
99
): Promise<string> {
1010
return new Promise((resolve, reject) => {
11-
ErrorHandler.getInstance().logCommand(`${command} ${args.join(" ")}`);
11+
ErrorHandler.logCommand(`${command} ${args.join(" ")}`);
1212
execFile(
1313
command,
1414
args,
1515
options,
1616
(error, stdout, stderr) => {
1717
if (error) {
18-
ErrorHandler.getInstance().logError(new Error(stderr));
18+
ErrorHandler.logError(new Error(stderr));
1919
resolve("");
2020
} else {
2121
resolve(stdout);

src/util/gitcommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function getGitCommand(): Promise<string> {
1818

1919
access(commandPath, FSConstant.X_OK, (err) => {
2020
if (err) {
21-
ErrorHandler.getInstance().logError(
21+
ErrorHandler.logError(
2222
new Error(
2323
`Can not execute "${
2424
commandPath

0 commit comments

Comments
 (0)