Skip to content

Commit

Permalink
#494 Logging Enhancements: transform empty args, and logging command …
Browse files Browse the repository at this point in the history
…invocations.
  • Loading branch information
mhutchie committed Apr 10, 2021
1 parent e44a48b commit cf681bb
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export class CommandManager extends Disposable {
*/
private registerCommand(command: string, callback: (...args: any[]) => any) {
this.registerDisposable(
vscode.commands.registerCommand(command, callback)
vscode.commands.registerCommand(command, (...args: any[]) => {
this.logger.log('Command Invoked: ' + command);
callback(...args);
})
);
}

Expand Down
13 changes: 9 additions & 4 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as vscode from 'vscode';
import { Disposable } from './utils/disposable';

const DOUBLE_QUOTE_REGEXP = /"/g;

/**
* Manages the Git Graph Logger, which writes log information to the Git Graph Output Channel.
*/
Expand Down Expand Up @@ -32,11 +34,14 @@ export class Logger extends Disposable {
* @param args The arguments passed to the command.
*/
public logCmd(cmd: string, args: string[]) {
this.log('> ' + cmd + ' ' + args.map((arg) => {
return arg.startsWith('--format=')
this.log('> ' + cmd + ' ' + args.map((arg) => arg === ''
? '""'
: arg.startsWith('--format=')
? '--format=...'
: arg.includes(' ') ? '"' + arg.replace(/"/g, '\\"') + '"' : arg;
}).join(' '));
: arg.includes(' ')
? '"' + arg.replace(DOUBLE_QUOTE_REGEXP, '\\"') + '"'
: arg
).join(' '));
}

/**
Expand Down
Loading

0 comments on commit cf681bb

Please sign in to comment.