Skip to content

Commit f5b042c

Browse files
improvement: show verbose log output by default (#7799)
* improvement: show verbose log output by default * chore(ci): force color output in CI * improvement(cli): tweak graph status output * chore: minor logging cleanup --------- Co-authored-by: Jon Edvald <edvald@gmail.com>
1 parent 5638647 commit f5b042c

File tree

15 files changed

+40
-30
lines changed

15 files changed

+40
-30
lines changed

.circleci/continue-config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ parameters:
2020
GARDEN_DISABLE_VERSION_CHECK: "true"
2121
GARDEN_DISABLE_ANALYTICS: "true"
2222
GARDEN_K8S_BUILD_SYNC_MODE: "mutagen"
23+
FORCE_COLOR: "1"
24+
TERM: "xterm-256color"
2325

2426
ubuntu-vm-runner: &ubuntu-vm-runner
2527
image: "ubuntu-2404:2024.08.1"

core/src/cli/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ ${renderCommands(commands)}
433433
}
434434

435435
const log = logger.createLog()
436-
log.verbose(`garden version: ${getPackageVersion()}`)
436+
log.debug(`garden version: ${getPackageVersion()}`)
437437

438438
// Load custom commands from current project (if applicable) and see if any match the arguments
439439
if (!command) {

core/src/cli/command-line.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { findProjectConfig } from "../config/base.js"
2020
import { GardenError, toGardenError } from "../exceptions.js"
2121
import type { Garden } from "../garden.js"
2222
import type { Log } from "../logger/log-entry.js"
23-
import { getTermWidth, renderDivider } from "../logger/util.js"
23+
import { getTerminalWidth, renderDivider } from "../logger/util.js"
2424
import type { GardenInstanceManager } from "../server/instance-manager.js"
2525
import { TypedEventEmitter } from "../util/events.js"
2626
import { uuidv4 } from "../util/random.js"
@@ -479,7 +479,7 @@ export class CommandLine extends TypedEventEmitter<CommandLineEvents> {
479479
private printWithDividers(text: string, title: string) {
480480
let width = max(text.split("\n").map((l) => stringWidth(l.trimEnd()))) || 0
481481
width += 2
482-
const termWidth = getTermWidth()
482+
const termWidth = getTerminalWidth()
483483
const minWidth = stringWidth(title) + 10
484484

485485
if (width > termWidth) {
@@ -688,7 +688,7 @@ ${styles.accent.underline("Keys:")}
688688
opts: PrepareParams["opts"]
689689
}) {
690690
const id = uuidv4()
691-
const width = getTermWidth() - 2
691+
const width = getTerminalWidth() - 2
692692

693693
const prepareParams: PrepareParams = {
694694
log: this.log,

core/src/cli/params.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ export const globalDisplayOptions = {
430430
${styles.highlight("info: 2")}, ${styles.highlight("verbose: 3")}, ${styles.highlight("debug: 4")},
431431
${styles.highlight("silly: 5")}.
432432
From the verbose log level onward action execution logs are also printed (e.g. test or run live log outputs).`,
433-
hints: "[choice] [default: info] [error || 0, warn || 1, info || 2, verbose || 3, debug || 4, silly || 5]",
434-
defaultValue: LogLevel[LogLevel.info],
433+
hints: "[choice] [default: verbose] [error || 0, warn || 1, info || 2, verbose || 3, debug || 4, silly || 5]",
434+
defaultValue: LogLevel[LogLevel.verbose],
435435
}),
436436
"output": new ChoicesParameter({
437437
aliases: ["o"],

core/src/graph/solver.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import chalk from "chalk"
2929
import { formatDuration } from "date-fns"
3030

3131
const taskStyle = styles.highlight.bold
32-
const statusUpdateIntervalMsec = 10000
32+
const statusUpdateIntervalMsec = 20000
3333

3434
export interface SolveOpts {
3535
statusOnly?: boolean
@@ -283,7 +283,7 @@ export class GraphSolver extends TypedEventEmitter<SolverEvents> {
283283
// TODO-0.13.1: currently a no-op, possibly not necessary
284284
}
285285

286-
renderStatus(batchId: string, startTime: Date) {
286+
private renderStatus(batchId: string, startTime: Date) {
287287
const requested = Object.values(this.requestedTasks[batchId]).sort((a, b) => {
288288
// Sort by key in ascending order
289289
return a.getKey().localeCompare(b.getKey())
@@ -327,7 +327,7 @@ export class GraphSolver extends TypedEventEmitter<SolverEvents> {
327327
chalk.yellow(listActions(formatResultDescription("aborted", abortedDeps), aborted)),
328328
chalk.red(listActions(formatResultDescription("failed", failedDeps), failed)),
329329
]
330-
const duration = formatDuration({ seconds: (new Date().getTime() - startTime.getTime()) / 1000 })
330+
const duration = formatDuration({ seconds: Math.round((new Date().getTime() - startTime.getTime()) / 1000) })
331331
const status = [
332332
renderDivider({
333333
color: chalk.magenta,
@@ -340,8 +340,12 @@ export class GraphSolver extends TypedEventEmitter<SolverEvents> {
340340
]
341341

342342
return {
343-
status: status.filter((s) => stripAnsi(s) !== "").join("\n"),
344-
content: stripAnsi(content.filter((s) => s !== "").join("\n")),
343+
status: status.filter((s) => stripAnsi(s).trim() !== "").join("\n"),
344+
content: content
345+
.map((s) => stripAnsi(s).trim())
346+
.filter((s) => s !== "")
347+
.join("\n")
348+
.trim(),
345349
}
346350
}
347351

core/src/logger/log-entry.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { omitUndefined } from "../util/objects.js"
1919
import { renderDuration } from "./util.js"
2020
import { styles } from "./styles.js"
2121
import { getStyle } from "./renderers.js"
22+
import hasAnsi from "has-ansi"
2223

2324
export type LogSymbol = keyof typeof logSymbols | "empty"
2425
export type TaskLogStatus = "active" | "success" | "error"
@@ -410,7 +411,7 @@ export abstract class Log<C extends BaseContext = LogContext> implements LogConf
410411
const style = resolved.level === LogLevel.info ? styles.success : getStyle(resolved.level)
411412
return this.log({
412413
...resolved,
413-
msg: transformMsg(this.getMsgWithDuration(resolved) || "", (msg) => style(msg)),
414+
msg: transformMsg(this.getMsgWithDuration(resolved) || "", (msg) => (hasAnsi(msg) ? msg : style(msg))),
414415
})
415416
}
416417

core/src/logger/renderers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function renderMsg(entry: LogEntry): string {
117117
const style = getStyle(level)
118118

119119
// For log levels higher than "info" we print the log level name.
120-
const logLevelName = entry.level > LogLevel.info ? `[${logLevelMap[entry.level]}] ` : ""
120+
const logLevelName = entry.level > LogLevel.verbose ? `[${logLevelMap[entry.level]}] ` : ""
121121

122122
const origin = context.origin ? `[${styles.italic(context.origin)}] ` : ""
123123

core/src/logger/util.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import stringWidth from "string-width"
1212
import { DEFAULT_BROWSER_DIVIDER_WIDTH } from "../constants.js"
1313
import { styles } from "./styles.js"
1414
import type { ChalkInstance } from "chalk"
15+
import ci from "ci-info"
1516

1617
// Add platforms/terminals?
1718
export function envSupportsEmoji() {
@@ -20,6 +21,11 @@ export function envSupportsEmoji() {
2021
)
2122
}
2223

24+
// Copied from https://github.com/sindresorhus/is-interactive
25+
export function isInteractive({ stream = process.stdout } = {}) {
26+
return Boolean(stream && stream.isTTY && process.env.TERM !== "dumb" && !("CI" in process.env)) && !ci.isCI
27+
}
28+
2329
let _overrideTerminalWidth: number | undefined
2430

2531
export function overrideTerminalWidth(width: number | undefined) {
@@ -93,7 +99,7 @@ export function renderDivider({
9399
}: DividerOpts = {}) {
94100
const pad = " "
95101
if (!width) {
96-
width = getTermWidth()
102+
width = getTerminalWidth()
97103
}
98104

99105
if (!color) {
@@ -112,11 +118,6 @@ export function renderDivider({
112118
return paddingString + dividerSideString + titleString + dividerSideString + paddingString
113119
}
114120

115-
export const getTermWidth = () => {
116-
// TODO: accept stdout as param
117-
return process.stdout?.columns || 100
118-
}
119-
120121
export function renderDuration(duration: number): string {
121122
return `(took ${duration} sec)`
122123
}

core/src/plugins/kubernetes/container/build/buildkit.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ export async function ensureBuildkit({
256256
timeoutSec: 600,
257257
})
258258

259-
deployLog.info("Done!")
260-
261259
return { authSecret, updated: true }
262260
})
263261
}

core/src/tasks/delete-deploy.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export class DeleteDeployTask extends BaseActionTask<DeployAction, DeployStatus>
9595
try {
9696
const output = await router.deploy.delete({ log: this.log, action, graph: this.graph })
9797
status = output.result
98-
this.log.info("Done!")
9998
} catch (err) {
10099
this.log.error(`Failed deleting ${action.name}`)
101100
throw err

0 commit comments

Comments
 (0)