|
| 1 | +--- |
| 2 | +title: Verbosity |
| 3 | +sidebar_position: 44 |
| 4 | +--- |
| 5 | + |
| 6 | +import {ChainedSnippets} from "../../src/components/MarkdownComponents.js"; |
| 7 | + |
| 8 | +Logging in Scala CLI can be controlled in a number of ways. |
| 9 | + |
| 10 | +```scala title=Hello.sc |
| 11 | +println("Hello") |
| 12 | +``` |
| 13 | + |
| 14 | +Logs, warnings and errors will be printed by default. |
| 15 | + |
| 16 | +<ChainedSnippets> |
| 17 | + |
| 18 | +```bash |
| 19 | +scala-cli Hello.sc |
| 20 | +``` |
| 21 | + |
| 22 | +```text |
| 23 | +Compiling project (Scala 3.2.2, JVM) |
| 24 | +Compiled project (Scala 3.2.2, JVM) |
| 25 | +Hello |
| 26 | +``` |
| 27 | + |
| 28 | +</ChainedSnippets> |
| 29 | + |
| 30 | +## Silencing logs with `-q` |
| 31 | + |
| 32 | +All logs except for errors can be silenced by passing the `-q` option. |
| 33 | + |
| 34 | +<ChainedSnippets> |
| 35 | + |
| 36 | +```bash |
| 37 | +scala-cli Hello.sc -q |
| 38 | +``` |
| 39 | + |
| 40 | +```text |
| 41 | +Hello |
| 42 | +``` |
| 43 | + |
| 44 | +</ChainedSnippets> |
| 45 | + |
| 46 | +## Increasing verbosity with `-v` |
| 47 | + |
| 48 | +You can increase verbosity by passing the `-v` option, to print debugging logs or gain extra context. |
| 49 | + |
| 50 | +<ChainedSnippets> |
| 51 | + |
| 52 | +```bash |
| 53 | +scala-cli Hello.sc -v |
| 54 | +``` |
| 55 | + |
| 56 | +```text |
| 57 | +Compiling project (Scala 3.2.2, JVM) |
| 58 | +Compiled project (Scala 3.2.2, JVM) |
| 59 | +Running ~/Library/Java/JavaVirtualMachines/corretto-17.0.5/Contents/Home/bin/java -cp ~/IdeaProjects/scala-cli-tests/hello1/.scala-build/project_853f6d1dbb-28a878fa14/classes/main:~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.2.2/scala3-library_3-3.2.2.jar:~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.10/scala-library-2.13.10.jar Hello_sc |
| 60 | +Hello |
| 61 | +``` |
| 62 | + |
| 63 | +</ChainedSnippets> |
| 64 | + |
| 65 | +You can increase verbosity even further by passing the `-v` option multiple times. |
| 66 | + |
| 67 | +<ChainedSnippets> |
| 68 | + |
| 69 | +```bash |
| 70 | +scala-cli Hello.sc -v -v |
| 71 | +``` |
| 72 | + |
| 73 | +```text |
| 74 | +Fetching List(Dependency(org.scala-lang:scala3-compiler_3, 3.2.2, Configuration(), Set(), Publication(, Type(), Extension(), Classifier()), false, true)), adding List(IvyRepository(Pattern(List(Const(file://~/Library/Caches/ScalaCli/local-repo/v0.2.0//), Var(organisation), Const(/), Var(module), Const(/), Opt(List(Const(scala_), Var(scalaVersion), Const(/))), Opt(List(Const(sbt_), Var(sbtVersion), Const(/))), Var(revision), Const(/), Var(type), Const(s/), Var(artifact), Opt(List(Const(-), Var(classifier))), Const(.), Var(ext))), None, None, true, true, true, false, None, true)) |
| 75 | +Found 13 artifacts: |
| 76 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.2.2/scala3-compiler_3-3.2.2.jar |
| 77 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-interfaces/3.2.2/scala3-interfaces-3.2.2.jar |
| 78 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.2.2/scala3-library_3-3.2.2.jar |
| 79 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/tasty-core_3/3.2.2/tasty-core_3-3.2.2.jar |
| 80 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-asm/9.3.0-scala-1/scala-asm-9.3.0-scala-1.jar |
| 81 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-sbt/compiler-interface/1.3.5/compiler-interface-1.3.5.jar |
| 82 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-reader/3.19.0/jline-reader-3.19.0.jar |
| 83 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-terminal/3.19.0/jline-terminal-3.19.0.jar |
| 84 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-terminal-jna/3.19.0/jline-terminal-jna-3.19.0.jar |
| 85 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.10/scala-library-2.13.10.jar |
| 86 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/google/protobuf/protobuf-java/3.7.0/protobuf-java-3.7.0.jar |
| 87 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-sbt/util-interface/1.3.0/util-interface-1.3.0.jar |
| 88 | + ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar |
| 89 | +(...) |
| 90 | +Hello |
| 91 | +
|
| 92 | +``` |
| 93 | + |
| 94 | +</ChainedSnippets> |
| 95 | + |
| 96 | +## Warnings suppression |
| 97 | + |
| 98 | +Some specific warning logs can be suppressed individually. |
| 99 | +That can be done by passing an appropriate option or by setting the appropriate global configuration key. |
| 100 | + |
| 101 | +### Warnings about `using` directives spread in multiple files |
| 102 | + |
| 103 | +```scala title=Deps1.sc |
| 104 | +//> using dep "com.lihaoyi::os-lib:0.9.1" |
| 105 | +``` |
| 106 | + |
| 107 | +```scala title=Deps2.sc |
| 108 | +//> using dep "com.lihaoyi::pprint:0.8.0" |
| 109 | +``` |
| 110 | + |
| 111 | +It is generally advised to not spread the `using` directives in multiple files, and put them in the |
| 112 | +optional `project.scala` configuration file. |
| 113 | +The relevant warnings can be suppressed with the `--suppress-outdated-dependency-warning` option. |
| 114 | + |
| 115 | +```bash |
| 116 | +scala-cli Deps1.sc Deps2.sc --suppress-outdated-dependency-warning |
| 117 | +``` |
| 118 | + |
| 119 | +Alternatively, the global config key `suppress-warning.directives-in-multiple-files` can be used. |
| 120 | + |
| 121 | +```bash |
| 122 | +scala-cli config suppress-warning.directives-in-multiple-files true |
| 123 | +``` |
| 124 | + |
| 125 | +### Warnings about experimental features' usage |
| 126 | + |
| 127 | +Using experimental features produces warnings, which can be suppressed with the `--suppress-experimental-warning` |
| 128 | +option. |
| 129 | + |
| 130 | +````bash |
| 131 | +scala-cli --power run --suppress-experimental-warning --markdown-snippet '# Markdown snippet |
| 132 | +with a code block |
| 133 | +```scala |
| 134 | +println("Hello") |
| 135 | +```' |
| 136 | +```` |
| 137 | + |
| 138 | +Alternatively, the global config key `suppress-warning.experimental-features` can be used. |
| 139 | + |
| 140 | +```bash |
| 141 | +scala-cli config suppress-warning.experimental-features true |
| 142 | +``` |
| 143 | + |
| 144 | +### Warnings about having outdated dependencies |
| 145 | + |
| 146 | +```scala title=OldDeps.sc |
| 147 | +//> using dep "com.lihaoyi::pprint:0.6.6" |
| 148 | +``` |
| 149 | + |
| 150 | +Depending on outdated libraries produces warnings, which can be suppressed with |
| 151 | +the `--suppress-outdated-dependencies-warning` option. |
| 152 | + |
| 153 | +````bash |
| 154 | +scala-cli OldDeps.sc --suppress-outdated-dependencies-warning |
| 155 | +```` |
| 156 | + |
| 157 | +Alternatively, the global config key `suppress-warning.outdated-dependencies-files` can be used. |
| 158 | + |
| 159 | +```bash |
| 160 | +scala-cli config suppress-warning.outdated-dependencies-files true |
| 161 | +``` |
0 commit comments