Skip to content

Commit

Permalink
improvement(exec): log build output with verbose logger
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 authored and thsig committed Nov 19, 2020
1 parent d178df6 commit bd7c81a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
15 changes: 8 additions & 7 deletions core/src/logger/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import nodeEmoji from "node-emoji"
import chalk from "chalk"
import chalk, { Chalk } from "chalk"
import CircularJSON from "circular-json"
import { LogNode, LogLevel } from "./log-node"
import { LogEntry, LogEntryParams, EmojiName } from "./log-entry"
Expand Down Expand Up @@ -211,13 +211,14 @@ export function renderDivider() {
return padEnd("", 80, "━")
}

export function renderMessageWithDivider(prefix: string, msg: string, isError: boolean) {
const color = isError ? chalk.red : chalk.white
export function renderMessageWithDivider(prefix: string, msg: string, isError: boolean, color?: Chalk) {
// Allow overwriting color as an escape hatch. Otherwise defaults to white or red in case of errors.
const msgColor = color || (isError ? chalk.red : chalk.white)
return dedent`
\n${color.bold(prefix)}
${color.bold(renderDivider())}
${hasAnsi(msg) ? msg : color(msg)}
${color.bold(renderDivider())}
\n${msgColor.bold(prefix)}
${msgColor.bold(renderDivider())}
${hasAnsi(msg) ? msg : msgColor(msg)}
${msgColor.bold(renderDivider())}
`
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/container/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function buildContainerModule({ ctx, module, log }: BuildModulePara
}

// Stream log to a status line
const outputStream = createOutputStream(log.placeholder({ level: LogLevel.debug }))
const outputStream = createOutputStream(log.placeholder({ level: LogLevel.verbose }))
const timeout = module.spec.build.timeout
const res = await containerHelpers.dockerCli({
cwd: module.buildPath,
Expand Down
8 changes: 7 additions & 1 deletion core/src/plugins/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { LogEntry } from "../logger/log-entry"
import { providerConfigBaseSchema } from "../config/provider"
import { ExecaError } from "execa"
import { artifactsTargetDescription } from "./container/config"
import chalk = require("chalk")
import { renderMessageWithDivider } from "../logger/util"

const execPathDoc = dedent`
By default, the command is run inside the Garden build directory (under .garden/build/<module-name>).
Expand Down Expand Up @@ -218,7 +220,7 @@ function getDefaultEnvVars(module: ExecModule) {
}
}

export async function buildExecModule({ module }: BuildModuleParams<ExecModule>): Promise<BuildResult> {
export async function buildExecModule({ module, log }: BuildModuleParams<ExecModule>): Promise<BuildResult> {
const output: BuildResult = {}
const { command } = module.spec.build

Expand All @@ -233,6 +235,10 @@ export async function buildExecModule({ module }: BuildModuleParams<ExecModule>)
output.buildLog = result.stdout + result.stderr
}

if (output.buildLog) {
const prefix = `Finished building module ${chalk.white(module.name)}. Here is the output:`
log.verbose(renderMessageWithDivider(prefix, output.buildLog, false, chalk.gray))
}
// keep track of which version has been built
const buildVersionFilePath = join(module.buildMetadataPath, GARDEN_BUILD_VERSION_FILENAME)
await writeModuleVersionFile(buildVersionFilePath, module.version)
Expand Down

0 comments on commit bd7c81a

Please sign in to comment.