diff --git a/cli/integration_tests/bad_flag.t b/cli/integration_tests/bad_flag.t index 827ca26859e19..23b21a9cab91d 100644 --- a/cli/integration_tests/bad_flag.t +++ b/cli/integration_tests/bad_flag.t @@ -19,7 +19,7 @@ Bad flag with an implied run command should display run flags note: to pass '--bad-flag' as a value, use '-- --bad-flag' - Usage: turbo <--cache-dir |--cache-workers |--concurrency |--continue|--dry-run []|--single-package|--filter |--force|--global-deps |--graph []|--ignore |--include-dependencies|--no-cache|--no-daemon|--no-deps|--output-logs |--only|--parallel|--pkg-inference-root |--profile |--remote-only|--scope |--since |TASKS|PASS_THROUGH_ARGS> + Usage: turbo <--cache-dir |--cache-workers |--concurrency |--continue|--dry-run []|--single-package|--filter |--force|--global-deps |--graph []|--ignore |--include-dependencies|--no-cache|--no-daemon|--no-deps|--output-logs |--only|--parallel|--pkg-inference-root |--profile |--remote-only|--scope |--since |--log-prefix |TASKS|PASS_THROUGH_ARGS> For more information, try '--help'. diff --git a/cli/integration_tests/no_args.t b/cli/integration_tests/no_args.t index 354eb328f12e6..8337dc43ec4f9 100644 --- a/cli/integration_tests/no_args.t +++ b/cli/integration_tests/no_args.t @@ -57,6 +57,7 @@ Make sure exit code is 2 when no args are passed --remote-only Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache --scope Specify package(s) to act as entry points for task execution. Supports globs --since Limit/Set scope to changed packages since a mergebase. This uses the git diff ${target_branch}... mechanism to identify which packages have changed + --log-prefix Use "none" to remove prefixes from task logs. Note that tasks running in parallel interleave their logs and prefix is the only way to identify which task produced a log [possible values: none] [1] $ ${TURBO} run Turbo error: at least one task must be specified diff --git a/cli/integration_tests/run_logging/log_prefix.t b/cli/integration_tests/run_logging/log_prefix.t new file mode 100644 index 0000000000000..fd405ccb90c81 --- /dev/null +++ b/cli/integration_tests/run_logging/log_prefix.t @@ -0,0 +1,78 @@ +Setup + $ . ${TESTDIR}/../setup.sh + $ . ${TESTDIR}/setup.sh $(pwd) ./monorepo + +# Run for the first time with --log-prefix=none + $ ${TURBO} run build --log-prefix=none + \xe2\x80\xa2 Packages in scope: app-a (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + cache miss, executing 74eb1b46ce8b29d3 + + \> build (re) + \> echo 'build app-a' (re) + + build app-a + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + +# Check that the cached logs don't have prefixes + $ cat app-a/.turbo/turbo-build.log + + \> build (re) + \> echo 'build app-a' (re) + + build app-a + +# Running again should get a cache hit and no prefixes + $ ${TURBO} run build --log-prefix=none + \xe2\x80\xa2 Packages in scope: app-a (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + cache miss, executing 3df2c74b2bfbc724 + + \> build (re) + \> echo 'build app-a' (re) + + build app-a + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + +# Running again withuot `--log-prefix` should get a cache hit, but should print prefixes this time + $ ${TURBO} run build + \xe2\x80\xa2 Packages in scope: app-a (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + app-a:build: cache hit, replaying output 3df2c74b2bfbc724 + app-a:build: + app-a:build: > build + app-a:build: > echo 'build app-a' + app-a:build: + app-a:build: build app-a + + Tasks: 1 successful, 1 total + Cached: 1 cached, 1 total + Time:\s*[\.0-9]+m?s >>> FULL TURBO (re) + + +# Running with bogus option + $ ${TURBO} run build --log-prefix=blah + ERROR invalid value 'blah' for '--log-prefix ' + [possible values: none] + + For more information, try '--help'. + + [1] + +# Running with missing value for option + $ ${TURBO} run build --log-prefix + ERROR a value is required for '--log-prefix ' but none was supplied + [possible values: none] + + For more information, try '--help'. + + [1] diff --git a/cli/integration_tests/run_logging/monorepo/app-a/package.json b/cli/integration_tests/run_logging/monorepo/app-a/package.json new file mode 100644 index 0000000000000..b685e7583b0c4 --- /dev/null +++ b/cli/integration_tests/run_logging/monorepo/app-a/package.json @@ -0,0 +1,6 @@ +{ + "name": "app-a", + "scripts": { + "build": "echo 'build app-a'" + } +} diff --git a/cli/integration_tests/run_logging/monorepo/package.json b/cli/integration_tests/run_logging/monorepo/package.json new file mode 100644 index 0000000000000..dba002fe7031d --- /dev/null +++ b/cli/integration_tests/run_logging/monorepo/package.json @@ -0,0 +1,6 @@ +{ + "name": "monorepo", + "workspaces": [ + "app-*" + ] +} diff --git a/cli/integration_tests/run_logging/monorepo/turbo.json b/cli/integration_tests/run_logging/monorepo/turbo.json new file mode 100644 index 0000000000000..f27ee6c9b5ebf --- /dev/null +++ b/cli/integration_tests/run_logging/monorepo/turbo.json @@ -0,0 +1,5 @@ +{ + "pipeline": { + "build": {} + } +} diff --git a/cli/integration_tests/run_logging/setup.sh b/cli/integration_tests/run_logging/setup.sh new file mode 100644 index 0000000000000..d771eae6cbad2 --- /dev/null +++ b/cli/integration_tests/run_logging/setup.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]}) +TARGET_DIR=$1 +TEST_DIR=$2 +cp -a ${SCRIPT_DIR}/$TEST_DIR/. ${TARGET_DIR}/ +${SCRIPT_DIR}/../setup_git.sh ${TARGET_DIR} diff --git a/cli/integration_tests/turbo_help.t b/cli/integration_tests/turbo_help.t index e639c7dce2472..6228efdb615ae 100644 --- a/cli/integration_tests/turbo_help.t +++ b/cli/integration_tests/turbo_help.t @@ -57,6 +57,7 @@ Test help flag --remote-only Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache --scope Specify package(s) to act as entry points for task execution. Supports globs --since Limit/Set scope to changed packages since a mergebase. This uses the git diff ${target_branch}... mechanism to identify which packages have changed + --log-prefix Use "none" to remove prefixes from task logs. Note that tasks running in parallel interleave their logs and prefix is the only way to identify which task produced a log [possible values: none] @@ -118,6 +119,7 @@ Test help flag --remote-only Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache --scope Specify package(s) to act as entry points for task execution. Supports globs --since Limit/Set scope to changed packages since a mergebase. This uses the git diff ${target_branch}... mechanism to identify which packages have changed + --log-prefix Use "none" to remove prefixes from task logs. Note that tasks running in parallel interleave their logs and prefix is the only way to identify which task produced a log [possible values: none] Test help flag for link command $ ${TURBO} link -h diff --git a/cli/internal/colorcache/colorcache.go b/cli/internal/colorcache/colorcache.go index b3d42c16c58be..08a15e83f6f7b 100644 --- a/cli/internal/colorcache/colorcache.go +++ b/cli/internal/colorcache/colorcache.go @@ -48,5 +48,9 @@ func (c *ColorCache) colorForKey(key string) colorFn { // color based on the cacheKey func (c *ColorCache) PrefixWithColor(cacheKey string, prefix string) string { colorFn := c.colorForKey(cacheKey) - return colorFn("%s: ", prefix) + if prefix != "" { + return colorFn("%s: ", prefix) + } + + return "" } diff --git a/cli/internal/run/real_run.go b/cli/internal/run/real_run.go index b8088971de606..fa3ddd44ff76b 100644 --- a/cli/internal/run/real_run.go +++ b/cli/internal/run/real_run.go @@ -151,9 +151,6 @@ func (ec *execContext) logError(log hclog.Logger, prefix string, err error) { func (ec *execContext) exec(ctx gocontext.Context, packageTask *nodes.PackageTask, deps dag.Set) error { cmdTime := time.Now() - prefix := packageTask.OutputPrefix(ec.isSinglePackage) - prettyPrefix := ec.colorCache.PrefixWithColor(packageTask.PackageName, prefix) - progressLogger := ec.logger.Named("") progressLogger.Debug("start") @@ -177,6 +174,17 @@ func (ec *execContext) exec(ctx gocontext.Context, packageTask *nodes.PackageTas progressLogger.Debug("done", "status", "skipped", "duration", time.Since(cmdTime)) return nil } + + var prefix string + var prettyPrefix string + if ec.rs.Opts.runOpts.logPrefix == "none" { + prefix = "" + } else { + prefix = packageTask.OutputPrefix(ec.isSinglePackage) + } + + prettyPrefix = ec.colorCache.PrefixWithColor(packageTask.PackageName, prefix) + // Cache --------------------------------------------- taskCache := ec.runCache.TaskCache(packageTask, hash) // Create a logger for replaying diff --git a/cli/internal/run/run.go b/cli/internal/run/run.go index 7f275b7c6c185..b9b94b08bf6b6 100644 --- a/cli/internal/run/run.go +++ b/cli/internal/run/run.go @@ -68,6 +68,7 @@ func ExecuteRun(ctx gocontext.Context, helper *cmdutil.Helper, signalWatcher *si func optsFromArgs(args *turbostate.ParsedArgsFromRust) (*Opts, error) { runPayload := args.Command.Run + opts := getDefaultOptions() // aliases := make(map[string]string) scope.OptsFromArgs(&opts.scopeOpts, args) @@ -76,6 +77,7 @@ func optsFromArgs(args *turbostate.ParsedArgsFromRust) (*Opts, error) { opts.cacheOpts.SkipFilesystem = runPayload.RemoteOnly opts.cacheOpts.OverrideDir = runPayload.CacheDir opts.cacheOpts.Workers = runPayload.CacheWorkers + opts.runOpts.logPrefix = runPayload.LogPrefix // Runcache flags opts.runcacheOpts.SkipReads = runPayload.Force diff --git a/cli/internal/run/run_spec.go b/cli/internal/run/run_spec.go index b837f9af8258e..3cac817fb3d52 100644 --- a/cli/internal/run/run_spec.go +++ b/cli/internal/run/run_spec.go @@ -74,4 +74,7 @@ type runOpts struct { graphFile string noDaemon bool singlePackage bool + + // logPrefix controls whether we should print a prefix in task logs + logPrefix string } diff --git a/cli/internal/turbostate/turbostate.go b/cli/internal/turbostate/turbostate.go index 0fb86d15c1c31..1f7a6568e0ebd 100644 --- a/cli/internal/turbostate/turbostate.go +++ b/cli/internal/turbostate/turbostate.go @@ -60,6 +60,7 @@ type RunPayload struct { SinglePackage bool `json:"single_package"` Tasks []string `json:"tasks"` PkgInferenceRoot string `json:"pkg_inference_root"` + LogPrefix string `json:"log_prefix"` } // Command consists of the data necessary to run a command. diff --git a/crates/turborepo-lib/src/cli.rs b/crates/turborepo-lib/src/cli.rs index 0473e2c3ebc25..f0060b8c23d47 100644 --- a/crates/turborepo-lib/src/cli.rs +++ b/crates/turborepo-lib/src/cli.rs @@ -352,6 +352,11 @@ pub struct RunArgs { /// to identify which packages have changed. #[clap(long)] pub since: Option, + /// Use "none" to remove prefixes from task logs. Note that tasks running + /// in parallel interleave their logs and prefix is the only way + /// to identify which task produced a log. + #[clap(long, value_enum)] + pub log_prefix: Option, // NOTE: The following two are hidden because clap displays them in the help text incorrectly: // > Usage: turbo [OPTIONS] [TASKS]... [-- ...] [COMMAND] #[clap(hide = true)] @@ -360,6 +365,12 @@ pub struct RunArgs { pub pass_through_args: Vec, } +#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Serialize)] +pub enum LogPrefix { + #[serde(rename = "none")] + None, +} + /// Runs the CLI by parsing arguments with clap, then either calling Rust code /// directly or returning a payload for the Go code to use. ///