Skip to content

Commit 46464f6

Browse files
authored
Add a verbosity guide doc (#1936)
1 parent 83b1679 commit 46464f6

File tree

4 files changed

+177
-8
lines changed

4 files changed

+177
-8
lines changed

website/docs/commands/basics.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ You can also pipe code to Scala CLI for execution:
252252
```bash
253253
echo 'println("Hello")' | scala-cli _.sc
254254
```
255-
255+
256256
```text
257257
Hello
258258
```
@@ -266,7 +266,7 @@ You can also pipe code to Scala CLI for execution:
266266
```bash
267267
echo '@main def hello() = println("Hello")' | scala-cli _.scala
268268
```
269-
269+
270270
```text
271271
Hello
272272
```
@@ -280,7 +280,7 @@ You can also pipe code to Scala CLI for execution:
280280
```bash
281281
echo 'class Hello { public static void main(String args[]) { System.out.println("Hello"); } }' | scala-cli _.java
282282
```
283-
283+
284284
```text
285285
Hello
286286
```
@@ -297,7 +297,7 @@ You can also pipe code to Scala CLI for execution:
297297
println("Hello")
298298
```' | scala-cli _.md
299299
```
300-
300+
301301
```text
302302
Hello
303303
```
@@ -369,9 +369,10 @@ Hello
369369
Hello
370370
-->
371371

372-
### Logging
372+
## Logging
373373

374-
To turn off logging in the application, pass the `-q` flag once. This will suppress all logging output except for errors:
374+
To turn off logging in the application, pass the `-q` flag once. This will suppress all logging output except for
375+
errors:
375376

376377
```scala title=Hello.scala
377378
object Hello extends App {
@@ -400,4 +401,10 @@ Compilation failed
400401
</ChainedSnippets>
401402

402403
Note that this will also suppress any logging related to tasks such as downloading dependencies, logs
403-
about the start of compilation, and so on.
404+
about the start of compilation, and so on.
405+
406+
## Warning suppression
407+
408+
Some particular warning logs can be suppressed, either for a particular command by passing an option or with a global
409+
config.
410+
More details can be found in the [verbosity guide](../guides/verbosity.md)

website/docs/guides/internals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Internals
3-
sidebar_position: 44
3+
sidebar_position: 49
44
---
55

66
Even though Scala CLI exposes a simple interface to users, quite a number of steps happen when compiling or running even a single source file.

website/docs/guides/intro.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Less introductory guides on specific topics.
3939
- [Scala.js](./scala-js.md) and [Scala Native](./scala-native.md) - learn how Scala CLI supports these non-JVM platforms
4040
- [Piping](./piping.md) - covers how Scala CLI allows to work with piped sources.
4141
- [Snippets](./snippets.md) - learn how to use command line snippets with Scala CLI.
42+
- [Verbosity](./verbosity.md) - learn how to control logs verbosity in Scala CLI.
4243
- [Internals](./internals.md) - learn about how Scala CLI works under the hood.
4344

4445
## ⚡️ `--power` mode guides

website/docs/guides/verbosity.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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

Comments
 (0)