Skip to content

Commit

Permalink
Add a setting to redirect debug logs to stderr instead of stdout.
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Hugs committed Mar 20, 2018
1 parent 317a4ba commit c980c6b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/exec/extension/_lib/vsix-manifest-builder.ts
Expand Up @@ -378,6 +378,7 @@ export class VsixManifestBuilder extends ManifestBuilder {
throw "Value for gitHubFlavoredMarkdown is invalid. Only boolean values are allowed.";
}
this.addProperty("Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown", value.toString());
break;
case "public":
if (typeof value === "boolean") {
let flags = _.get(this.data, "PackageManifest.Metadata[0].GalleryFlags[0]", "").split(" ");
Expand Down
23 changes: 21 additions & 2 deletions app/lib/tfcommand.ts
Expand Up @@ -36,6 +36,7 @@ export interface CoreArguments {
help: args.BooleanArgument;
noPrompt: args.BooleanArgument;
noColor: args.BooleanArgument;
debugLogStream: args.StringArgument;
}

export interface Executor<TResult> {
Expand Down Expand Up @@ -317,6 +318,13 @@ export abstract class TfCommand<TArguments extends CoreArguments, TResult> {
args.BooleanArgument,
"false",
);
this.registerCommandArgument(
"debugLogStream",
"Debug message logging stream (stdout | stderr)",
"Stream used for writing debug logs (stdout or stderr)",
args.StringArgument,
"stdout",
);
}

/**
Expand Down Expand Up @@ -537,7 +545,7 @@ export abstract class TfCommand<TArguments extends CoreArguments, TResult> {
}

result += eol + cyan("Global arguments:") + eol;
["help", "save", "noColor", "noPrompt", "output", "json", "traceLevel"].forEach(arg => {
["help", "save", "noColor", "noPrompt", "output", "json", "traceLevel", "debugLogStream"].forEach(arg => {
result += singleArgData(arg, 9);
});

Expand Down Expand Up @@ -603,10 +611,21 @@ export abstract class TfCommand<TArguments extends CoreArguments, TResult> {
})
.then(() => {
return version.getTfxVersion().then(async semVer => {
const [outputType, traceLevel] = await Promise.all([
const [outputType, traceLevel, debugLogStream] = await Promise.all([
this.commandArgs.output.val(),
this.commandArgs.traceLevel.val(),
this.commandArgs.debugLogStream.val(),
]);
switch (debugLogStream) {
case "stdout":
trace.debugLogStream = console.log;
break;
case "stderr":
trace.debugLogStream = console.error;
break;
default:
throw new Error("Parameter --debug-log-stream must have value 'stdout' or 'stderr'.");
}
switch (traceLevel && traceLevel.toLowerCase()) {
case "none":
trace.traceLevel = trace.TraceLevel.None;
Expand Down
5 changes: 3 additions & 2 deletions app/lib/trace.ts
Expand Up @@ -9,6 +9,7 @@ export const enum TraceLevel {
}

export let traceLevel: TraceLevel = debugTracingEnvVar ? TraceLevel.Debug : TraceLevel.Info;
export let debugLogStream = console.log;

export type printable = string | number | boolean;

Expand Down Expand Up @@ -37,14 +38,14 @@ export function warn(msg: any, ...replacements: printable[]): void {
export function debugArea(msg: any, area: string) {
debugTracingEnvVar = process.env["TFX_TRACE_" + area.toUpperCase()];
if (debugTracingEnvVar) {
log(colors.cyan(new Date().toISOString() + " : "), msg, colors.grey, []);
log(colors.cyan(new Date().toISOString() + " : "), msg, colors.grey, [], debugLogStream);
}
debugTracingEnvVar = process.env["TFX_TRACE"];
}

export function debug(msg: any, ...replacements: printable[]) {
if (traceLevel >= TraceLevel.Debug) {
log(colors.cyan(new Date().toISOString() + " : "), msg, colors.grey, replacements);
log(colors.cyan(new Date().toISOString() + " : "), msg, colors.grey, replacements, debugLogStream);
}
}

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -6,6 +6,7 @@
"declaration": false,
"sourceMap": true,
"newLine": "LF",
"noFallthroughCasesInSwitch": true,

// Note: dom is specified below so that the JSZip d.ts can use the Blob type.
"lib": ["es5", "es2015", "es6", "dom"],
Expand Down

0 comments on commit c980c6b

Please sign in to comment.