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:
parent
5cf429d64e
commit
e1c5cea2e7
|
@ -205,8 +205,6 @@ var GitClient = /** @class */ (function () {
|
||||||
*/
|
*/
|
||||||
function GitClient(githubToken, config, baseDir) {
|
function GitClient(githubToken, config, baseDir) {
|
||||||
this.githubToken = githubToken;
|
this.githubToken = githubToken;
|
||||||
/** Whether verbose logging of Git actions should be used. */
|
|
||||||
this.verboseLogging = true;
|
|
||||||
/** The OAuth scopes available for the provided Github token. */
|
/** The OAuth scopes available for the provided Github token. */
|
||||||
this._cachedOauthScopes = null;
|
this._cachedOauthScopes = null;
|
||||||
/**
|
/**
|
||||||
|
@ -254,10 +252,9 @@ var GitClient = /** @class */ (function () {
|
||||||
}
|
}
|
||||||
GitClient.authenticated = new GitClient(token);
|
GitClient.authenticated = new GitClient(token);
|
||||||
};
|
};
|
||||||
/** Set the verbose logging state of the GitClient instance. */
|
/** Set the verbose logging state of the GitClient class. */
|
||||||
GitClient.prototype.setVerboseLoggingState = function (verbose) {
|
GitClient.setVerboseLoggingState = function (verbose) {
|
||||||
this.verboseLogging = verbose;
|
this.verboseLogging = verbose;
|
||||||
return this;
|
|
||||||
};
|
};
|
||||||
/** Executes the given git command. Throws if the command fails. */
|
/** Executes the given git command. Throws if the command fails. */
|
||||||
GitClient.prototype.run = function (args, options) {
|
GitClient.prototype.run = function (args, options) {
|
||||||
|
@ -283,9 +280,10 @@ var GitClient = /** @class */ (function () {
|
||||||
throw new DryRunError();
|
throw new DryRunError();
|
||||||
}
|
}
|
||||||
// To improve the debugging experience in case something fails, we print all executed Git
|
// 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
|
// commands at the DEBUG level to better understand the git actions occuring. Verbose logging,
|
||||||
// executed, this debugging information should be logged at different logging levels.
|
// always logging at the INFO level, can be enabled either by setting the verboseLogging
|
||||||
var printFn = (!this.verboseLogging || options.stdio === 'ignore') ? debug : info;
|
// 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
|
// 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.
|
// to share errors with others if the tool failed, and we do not want to leak tokens.
|
||||||
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
|
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
|
||||||
|
@ -424,16 +422,16 @@ var GitClient = /** @class */ (function () {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
GitClient.prototype.determineBaseDir = 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;
|
var _a = this.runGraceful(['rev-parse', '--show-toplevel']), stdout = _a.stdout, stderr = _a.stderr, status = _a.status;
|
||||||
if (status !== 0) {
|
if (status !== 0) {
|
||||||
throw Error("Unable to find the path to the base directory of the repository.\n" +
|
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" +
|
"Was the command run from inside of the repo?\n\n" +
|
||||||
("ERROR:\n " + stderr));
|
("ERROR:\n " + stderr));
|
||||||
}
|
}
|
||||||
this.setVerboseLoggingState(true);
|
|
||||||
return stdout.trim();
|
return stdout.trim();
|
||||||
};
|
};
|
||||||
|
/** Whether verbose logging of Git actions should be used. */
|
||||||
|
GitClient.verboseLogging = false;
|
||||||
return GitClient;
|
return GitClient;
|
||||||
}());
|
}());
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {GitClient} from '../../utils/git/index';
|
|
||||||
import {getCaretakerConfig} from '../config';
|
import {getCaretakerConfig} from '../config';
|
||||||
|
|
||||||
import {CiModule} from './ci';
|
import {CiModule} from './ci';
|
||||||
|
@ -24,8 +23,6 @@ const moduleList = [
|
||||||
|
|
||||||
/** Check the status of services which Angular caretakers need to monitor. */
|
/** Check the status of services which Angular caretakers need to monitor. */
|
||||||
export async function checkServiceStatuses() {
|
export async function checkServiceStatuses() {
|
||||||
// Set the verbose logging state of the GitClient.
|
|
||||||
GitClient.getAuthenticatedInstance().setVerboseLoggingState(false);
|
|
||||||
/** The configuration for the caretaker commands. */
|
/** The configuration for the caretaker commands. */
|
||||||
const config = getCaretakerConfig();
|
const config = getCaretakerConfig();
|
||||||
/** List of instances of Caretaker Check modules */
|
/** List of instances of Caretaker Check modules */
|
||||||
|
|
|
@ -373,8 +373,6 @@ var GitClient = /** @class */ (function () {
|
||||||
*/
|
*/
|
||||||
function GitClient(githubToken, config, baseDir) {
|
function GitClient(githubToken, config, baseDir) {
|
||||||
this.githubToken = githubToken;
|
this.githubToken = githubToken;
|
||||||
/** Whether verbose logging of Git actions should be used. */
|
|
||||||
this.verboseLogging = true;
|
|
||||||
/** The OAuth scopes available for the provided Github token. */
|
/** The OAuth scopes available for the provided Github token. */
|
||||||
this._cachedOauthScopes = null;
|
this._cachedOauthScopes = null;
|
||||||
/**
|
/**
|
||||||
|
@ -422,10 +420,9 @@ var GitClient = /** @class */ (function () {
|
||||||
}
|
}
|
||||||
GitClient.authenticated = new GitClient(token);
|
GitClient.authenticated = new GitClient(token);
|
||||||
};
|
};
|
||||||
/** Set the verbose logging state of the GitClient instance. */
|
/** Set the verbose logging state of the GitClient class. */
|
||||||
GitClient.prototype.setVerboseLoggingState = function (verbose) {
|
GitClient.setVerboseLoggingState = function (verbose) {
|
||||||
this.verboseLogging = verbose;
|
this.verboseLogging = verbose;
|
||||||
return this;
|
|
||||||
};
|
};
|
||||||
/** Executes the given git command. Throws if the command fails. */
|
/** Executes the given git command. Throws if the command fails. */
|
||||||
GitClient.prototype.run = function (args, options) {
|
GitClient.prototype.run = function (args, options) {
|
||||||
|
@ -451,9 +448,10 @@ var GitClient = /** @class */ (function () {
|
||||||
throw new DryRunError();
|
throw new DryRunError();
|
||||||
}
|
}
|
||||||
// To improve the debugging experience in case something fails, we print all executed Git
|
// 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
|
// commands at the DEBUG level to better understand the git actions occuring. Verbose logging,
|
||||||
// executed, this debugging information should be logged at different logging levels.
|
// always logging at the INFO level, can be enabled either by setting the verboseLogging
|
||||||
var printFn = (!this.verboseLogging || options.stdio === 'ignore') ? debug : info;
|
// 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
|
// 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.
|
// to share errors with others if the tool failed, and we do not want to leak tokens.
|
||||||
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
|
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
|
||||||
|
@ -592,16 +590,16 @@ var GitClient = /** @class */ (function () {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
GitClient.prototype.determineBaseDir = 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;
|
var _a = this.runGraceful(['rev-parse', '--show-toplevel']), stdout = _a.stdout, stderr = _a.stderr, status = _a.status;
|
||||||
if (status !== 0) {
|
if (status !== 0) {
|
||||||
throw Error("Unable to find the path to the base directory of the repository.\n" +
|
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" +
|
"Was the command run from inside of the repo?\n\n" +
|
||||||
("ERROR:\n " + stderr));
|
("ERROR:\n " + stderr));
|
||||||
}
|
}
|
||||||
this.setVerboseLoggingState(true);
|
|
||||||
return stdout.trim();
|
return stdout.trim();
|
||||||
};
|
};
|
||||||
|
/** Whether verbose logging of Git actions should be used. */
|
||||||
|
GitClient.verboseLogging = false;
|
||||||
return GitClient;
|
return GitClient;
|
||||||
}());
|
}());
|
||||||
/**
|
/**
|
||||||
|
@ -1541,8 +1539,6 @@ const moduleList = [
|
||||||
/** Check the status of services which Angular caretakers need to monitor. */
|
/** Check the status of services which Angular caretakers need to monitor. */
|
||||||
function checkServiceStatuses() {
|
function checkServiceStatuses() {
|
||||||
return tslib.__awaiter(this, void 0, void 0, function* () {
|
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. */
|
/** The configuration for the caretaker commands. */
|
||||||
const config = getCaretakerConfig();
|
const config = getCaretakerConfig();
|
||||||
/** List of instances of Caretaker Check modules */
|
/** List of instances of Caretaker Check modules */
|
||||||
|
|
|
@ -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.
|
* 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);
|
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. */
|
/** The configuration, containing the github specific configuration. */
|
||||||
private config: NgDevConfig;
|
private config: NgDevConfig;
|
||||||
/** Whether verbose logging of Git actions should be used. */
|
|
||||||
private verboseLogging = true;
|
|
||||||
/** The OAuth scopes available for the provided Github token. */
|
/** The OAuth scopes available for the provided Github token. */
|
||||||
private _cachedOauthScopes: Promise<string[]>|null = null;
|
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. */
|
/** 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);
|
const result = this.runGraceful(args, options);
|
||||||
if (result.status !== 0) {
|
if (result.status !== 0) {
|
||||||
throw new GitCommandError(this, args);
|
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
|
* if there is any stderr output, the output will be printed. This makes it easier to
|
||||||
* info failed commands.
|
* info failed commands.
|
||||||
*/
|
*/
|
||||||
runGraceful(args: string[], options: SpawnSyncOptions = {}): SpawnSyncReturns<string> {
|
runGraceful(args: string[], options: GitClientRunOptions = {}): SpawnSyncReturns<string> {
|
||||||
/** The git command to be run. */
|
/** The git command to be run. */
|
||||||
const gitCommand = args[0];
|
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
|
// 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
|
// commands at the DEBUG level to better understand the git actions occuring. Verbose logging,
|
||||||
// executed, this debugging information should be logged at different logging levels.
|
// always logging at the INFO level, can be enabled either by setting the verboseLogging
|
||||||
const printFn = (!this.verboseLogging || options.stdio === 'ignore') ? debug : info;
|
// 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
|
// 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.
|
// to share errors with others if the tool failed, and we do not want to leak tokens.
|
||||||
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
|
printFn('Executing: git', this.omitGithubTokenFromMessage(args.join(' ')));
|
||||||
|
@ -321,7 +326,6 @@ export class GitClient<Authenticated extends boolean> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private determineBaseDir() {
|
private determineBaseDir() {
|
||||||
this.setVerboseLoggingState(false);
|
|
||||||
const {stdout, stderr, status} = this.runGraceful(['rev-parse', '--show-toplevel']);
|
const {stdout, stderr, status} = this.runGraceful(['rev-parse', '--show-toplevel']);
|
||||||
if (status !== 0) {
|
if (status !== 0) {
|
||||||
throw Error(
|
throw Error(
|
||||||
|
@ -329,7 +333,6 @@ export class GitClient<Authenticated extends boolean> {
|
||||||
`Was the command run from inside of the repo?\n\n` +
|
`Was the command run from inside of the repo?\n\n` +
|
||||||
`ERROR:\n ${stderr}`);
|
`ERROR:\n ${stderr}`);
|
||||||
}
|
}
|
||||||
this.setVerboseLoggingState(true);
|
|
||||||
return stdout.trim();
|
return stdout.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue