Skip to content

Commit

Permalink
fix(dev-infra): set the default LogLevel of GitClient logging to DEBUG (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
josephperrott authored and alxhub committed May 7, 2021
1 parent 5cf429d commit e1c5cea
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 40 deletions.
18 changes: 8 additions & 10 deletions dev-infra/build-worker.js
Expand Up @@ -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;
/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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(' ')));
Expand Down Expand Up @@ -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;
}());
/**
Expand Down
3 changes: 0 additions & 3 deletions dev-infra/caretaker/check/check.ts
Expand Up @@ -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';
Expand All @@ -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 */
Expand Down
20 changes: 8 additions & 12 deletions dev-infra/ng-dev.js
Expand Up @@ -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;
/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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(' ')));
Expand Down Expand Up @@ -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;
}());
/**
Expand Down Expand Up @@ -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 */
Expand Down
33 changes: 18 additions & 15 deletions dev-infra/utils/git/index.ts
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
/**
Expand Down Expand Up @@ -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);
Expand All @@ -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];

Expand All @@ -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(' ')));
Expand Down Expand Up @@ -321,15 +326,13 @@ 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(
`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();
}
}
Expand Down

0 comments on commit e1c5cea

Please sign in to comment.