fix(dev-infra): set the default LogLevel of GitClient logging to DEBUG (#41899)

Previously by default GitClient would log the commands it was executing at the
INFO level. This change moves the default level of this logging to DEBUG, while
still allowing callers of the methods to set the log level back to INFO.

PR Close #41899
This commit is contained in:
Joey Perrott 2021-04-30 09:33:40 -07:00 committed by Alex Rickabaugh
parent 5cf429d64e
commit e1c5cea2e7
4 changed files with 34 additions and 40 deletions

View File

@ -205,8 +205,6 @@ var GitClient = /** @class */ (function () {
*/
function GitClient(githubToken, config, baseDir) {
this.githubToken = githubToken;
/** Whether verbose logging of Git actions should be used. */
this.verboseLogging = true;
/** The OAuth scopes available for the provided Github token. */
this._cachedOauthScopes = null;
/**
@ -254,10 +252,9 @@ var GitClient = /** @class */ (function () {
}
GitClient.authenticated = new GitClient(token);
};
/** Set the verbose logging state of the GitClient instance. */
GitClient.prototype.setVerboseLoggingState = function (verbose) {
/** Set the verbose logging state of the GitClient class. */
GitClient.setVerboseLoggingState = function (verbose) {
this.verboseLogging = verbose;
return this;
};
/** Executes the given git command. Throws if the command fails. */
GitClient.prototype.run = function (args, options) {
@ -283,9 +280,10 @@ var GitClient = /** @class */ (function () {
throw new DryRunError();
}
// To improve the debugging experience in case something fails, we print all executed Git
// commands to better understand the git actions occuring. Depending on the command being
// executed, this debugging information should be logged at different logging levels.
var printFn = (!this.verboseLogging || options.stdio === 'ignore') ? debug : info;
// commands at the DEBUG level to better understand the git actions occuring. Verbose logging,
// always logging at the INFO level, can be enabled either by setting the verboseLogging
// property on the GitClient class or the options object provided to the method.
var printFn = (GitClient.verboseLogging || options.verboseLogging) ? info : debug;
// Note that we do not want to print the token if it is contained in the command. It's common
// to share errors with others if the tool failed, and we do not want to leak tokens.
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
@ -424,16 +422,16 @@ var GitClient = /** @class */ (function () {
});
};
GitClient.prototype.determineBaseDir = function () {
this.setVerboseLoggingState(false);
var _a = this.runGraceful(['rev-parse', '--show-toplevel']), stdout = _a.stdout, stderr = _a.stderr, status = _a.status;
if (status !== 0) {
throw Error("Unable to find the path to the base directory of the repository.\n" +
"Was the command run from inside of the repo?\n\n" +
("ERROR:\n " + stderr));
}
this.setVerboseLoggingState(true);
return stdout.trim();
};
/** Whether verbose logging of Git actions should be used. */
GitClient.verboseLogging = false;
return GitClient;
}());
/**

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {GitClient} from '../../utils/git/index';
import {getCaretakerConfig} from '../config';
import {CiModule} from './ci';
@ -24,8 +23,6 @@ const moduleList = [
/** Check the status of services which Angular caretakers need to monitor. */
export async function checkServiceStatuses() {
// Set the verbose logging state of the GitClient.
GitClient.getAuthenticatedInstance().setVerboseLoggingState(false);
/** The configuration for the caretaker commands. */
const config = getCaretakerConfig();
/** List of instances of Caretaker Check modules */

View File

@ -373,8 +373,6 @@ var GitClient = /** @class */ (function () {
*/
function GitClient(githubToken, config, baseDir) {
this.githubToken = githubToken;
/** Whether verbose logging of Git actions should be used. */
this.verboseLogging = true;
/** The OAuth scopes available for the provided Github token. */
this._cachedOauthScopes = null;
/**
@ -422,10 +420,9 @@ var GitClient = /** @class */ (function () {
}
GitClient.authenticated = new GitClient(token);
};
/** Set the verbose logging state of the GitClient instance. */
GitClient.prototype.setVerboseLoggingState = function (verbose) {
/** Set the verbose logging state of the GitClient class. */
GitClient.setVerboseLoggingState = function (verbose) {
this.verboseLogging = verbose;
return this;
};
/** Executes the given git command. Throws if the command fails. */
GitClient.prototype.run = function (args, options) {
@ -451,9 +448,10 @@ var GitClient = /** @class */ (function () {
throw new DryRunError();
}
// To improve the debugging experience in case something fails, we print all executed Git
// commands to better understand the git actions occuring. Depending on the command being
// executed, this debugging information should be logged at different logging levels.
var printFn = (!this.verboseLogging || options.stdio === 'ignore') ? debug : info;
// commands at the DEBUG level to better understand the git actions occuring. Verbose logging,
// always logging at the INFO level, can be enabled either by setting the verboseLogging
// property on the GitClient class or the options object provided to the method.
var printFn = (GitClient.verboseLogging || options.verboseLogging) ? info : debug;
// Note that we do not want to print the token if it is contained in the command. It's common
// to share errors with others if the tool failed, and we do not want to leak tokens.
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
@ -592,16 +590,16 @@ var GitClient = /** @class */ (function () {
});
};
GitClient.prototype.determineBaseDir = function () {
this.setVerboseLoggingState(false);
var _a = this.runGraceful(['rev-parse', '--show-toplevel']), stdout = _a.stdout, stderr = _a.stderr, status = _a.status;
if (status !== 0) {
throw Error("Unable to find the path to the base directory of the repository.\n" +
"Was the command run from inside of the repo?\n\n" +
("ERROR:\n " + stderr));
}
this.setVerboseLoggingState(true);
return stdout.trim();
};
/** Whether verbose logging of Git actions should be used. */
GitClient.verboseLogging = false;
return GitClient;
}());
/**
@ -1541,8 +1539,6 @@ const moduleList = [
/** Check the status of services which Angular caretakers need to monitor. */
function checkServiceStatuses() {
return tslib.__awaiter(this, void 0, void 0, function* () {
// Set the verbose logging state of the GitClient.
GitClient.getAuthenticatedInstance().setVerboseLoggingState(false);
/** The configuration for the caretaker commands. */
const config = getCaretakerConfig();
/** List of instances of Caretaker Check modules */

View File

@ -34,6 +34,11 @@ export class GitCommandError extends Error {
}
}
/** The options available for `GitClient`'s `run` and `runGraceful` methods. */
type GitClientRunOptions = SpawnSyncOptions&{
verboseLogging?: boolean;
};
/**
* Common client for performing Git interactions with a given remote.
*
@ -83,10 +88,15 @@ export class GitClient<Authenticated extends boolean> {
GitClient.authenticated = new GitClient(token);
}
/** Set the verbose logging state of the GitClient class. */
static setVerboseLoggingState(verbose: boolean) {
this.verboseLogging = verbose;
}
/** Whether verbose logging of Git actions should be used. */
private static verboseLogging = false;
/** The configuration, containing the github specific configuration. */
private config: NgDevConfig;
/** Whether verbose logging of Git actions should be used. */
private verboseLogging = true;
/** The OAuth scopes available for the provided Github token. */
private _cachedOauthScopes: Promise<string[]>|null = null;
/**
@ -124,14 +134,8 @@ export class GitClient<Authenticated extends boolean> {
}
}
/** Set the verbose logging state of the GitClient instance. */
setVerboseLoggingState(verbose: boolean): this {
this.verboseLogging = verbose;
return this;
}
/** Executes the given git command. Throws if the command fails. */
run(args: string[], options?: SpawnSyncOptions): Omit<SpawnSyncReturns<string>, 'status'> {
run(args: string[], options?: GitClientRunOptions): Omit<SpawnSyncReturns<string>, 'status'> {
const result = this.runGraceful(args, options);
if (result.status !== 0) {
throw new GitCommandError(this, args);
@ -146,7 +150,7 @@ export class GitClient<Authenticated extends boolean> {
* if there is any stderr output, the output will be printed. This makes it easier to
* info failed commands.
*/
runGraceful(args: string[], options: SpawnSyncOptions = {}): SpawnSyncReturns<string> {
runGraceful(args: string[], options: GitClientRunOptions = {}): SpawnSyncReturns<string> {
/** The git command to be run. */
const gitCommand = args[0];
@ -156,9 +160,10 @@ export class GitClient<Authenticated extends boolean> {
}
// To improve the debugging experience in case something fails, we print all executed Git
// commands to better understand the git actions occuring. Depending on the command being
// executed, this debugging information should be logged at different logging levels.
const printFn = (!this.verboseLogging || options.stdio === 'ignore') ? debug : info;
// commands at the DEBUG level to better understand the git actions occuring. Verbose logging,
// always logging at the INFO level, can be enabled either by setting the verboseLogging
// property on the GitClient class or the options object provided to the method.
const printFn = (GitClient.verboseLogging || options.verboseLogging) ? info : debug;
// Note that we do not want to print the token if it is contained in the command. It's common
// to share errors with others if the tool failed, and we do not want to leak tokens.
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
@ -321,7 +326,6 @@ export class GitClient<Authenticated extends boolean> {
}
private determineBaseDir() {
this.setVerboseLoggingState(false);
const {stdout, stderr, status} = this.runGraceful(['rev-parse', '--show-toplevel']);
if (status !== 0) {
throw Error(
@ -329,7 +333,6 @@ export class GitClient<Authenticated extends boolean> {
`Was the command run from inside of the repo?\n\n` +
`ERROR:\n ${stderr}`);
}
this.setVerboseLoggingState(true);
return stdout.trim();
}
}