Skip to content

Commit 9a85e1f

Browse files
committed
Logging
1 parent 12e673d commit 9a85e1f

File tree

8 files changed

+59
-24
lines changed

8 files changed

+59
-24
lines changed

big list of undocumented features.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,6 @@
113113
- **MathJax 3 for math rendering** — MathJax 3 renders LaTeX math in Markdown and outputs. (#1947, #2165, #2803)
114114
---
115115

116-
## 7. Logging
117-
118-
- **Julia Logging integration**`@info`, `@warn`, `@error`, `@debug` messages appear in notebook cell output. (#437)
119-
- **Logs relayed to browser console** — Log messages also appear in the browser developer console. (#496)
120-
- **Log level display** — Different log levels are styled differently. (#498)
121-
- **Vertical log layout** — Logs are displayed vertically below cell output. (#2297)
122-
- **Logs from async cells at source** — Log messages from async code appear under the correct cell. (#2115)
123-
- **Scoped loggers per cell** — Each cell has its own logger context for correct attribution. (#2249)
124-
- **`maxlog` keyword support** — The `maxlog` keyword in `@info` is respected to limit repeated log messages. (#1877, #1911, #2493)
125-
- **ProgressLogging support**`ProgressLogging.@progress` shows progress bars in the notebook. (#2222, #2966)
126-
- **Custom progress bar names** — Custom names for progress bars from `@progress` are shown. (#2966)
127-
- **Show `stdout` and `stderr` in notebook** — Print statements go to a terminal-style output popup instead of the terminal. (#1957)
128-
- **Stdout popup generalized** — Popup system generalized to support multiple popup types. (#1956)
129-
- **Stdout logging scoped per notebook** — Log channels are scoped to individual notebooks. (#2027)
130-
- **`yield()` around logger redirect** — Fixed a bug where logs got stuck by adding yields. (#2026)
131-
- **Log message format for exceptions** — Exception and backtrace in logs are formatted like errors. (#1962)
132-
- **Fallback for errors in logging** — If logging itself throws, the error is handled gracefully. (#3013)
133-
- **Fix logging with ProgressLogging v1.6** — Compat fix for the latest ProgressLogging. (#3440)
134-
135-
---
136116

137117
## 8. HTML Export & Static Notebooks
138118

47.6 KB
Loading

src/assets/img/log hiding.png

14.3 KB
Loading

src/assets/img/log levels.png

15.9 KB
Loading

src/assets/img/log simple i.png

18.5 KB
Loading

src/assets/img/log simple.png

16.2 KB
Loading

src/assets/img/log stdout.png

18.2 KB
Loading

src/en/docs/logging.jlmd

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@ order: 21
1010

1111
To help with debugging your code, Pluto supports showing messages printed with the [standard library Logging module](https://docs.julialang.org/en/v1/stdlib/Logging/). This can be done using the `@info`, `@warn` and `@error` macro.
1212

13+
For example, you can use `@info` somewhere in your code to see the value of a variable while your code runs:
14+
15+
```julia
16+
begin
17+
result = 0
18+
19+
for i in 1:5
20+
x = i^2
21+
@info("Current value", x)
22+
result += x
23+
end
24+
result
25+
end
26+
```
27+
28+
<img alt="Screenshot of the log messages from the previous code example." src="$(root_url)/assets/img/log simple.png" width="1040" height="730" style="max-width: 500px;">
29+
30+
31+
You can give `@info` as many arguments as you want. The first argument is a message, and the other arguments are key-value pairs that will be shown in the logs. For example, we can add `i` to the log.
32+
33+
34+
<img alt="Screenshot of the log messages with 'i' added." src="$(root_url)/assets/img/log simple i.png" width="1040" height="822" style="max-width: 500px;">
35+
36+
## Log levels: `@debug`, `@info`, `@warn`, `@error`
37+
Each log message can have a _level_ or _severity_. This makes it easy to distinguish between different types of log messages. To change the log level, you can use the corresponding macro: `@debug`, `@warn` or `@error` instead of `@info`.
38+
39+
40+
<img alt="Screenshot of different log levels displayed in different colors." src="$(root_url)/assets/img/log levels.png" width="1040" height="1106" style="max-width: 500px;">
41+
42+
`@debug` is useful when sharing your work as a package. `@debug` logs will only display in your notebook, but not when someone else imports your code/package.
1343

1444

1545
<!--
@@ -21,18 +51,43 @@ A simple way to disable all logs for a notebook is to change the global logger o
2151

2252
-->
2353

24-
### Disabling logs for a cell
54+
## Special log arguments
55+
Pluto will use its rich object inspector to display the arguments of log messages. This means that you can log complex objects like `Dict`s, `DataFrame`s, or even `plot`s, and they will be displayed in a nice way in the logs.
56+
57+
Here is an example of logging a `Vector`, and an `Exception`:
58+
59+
<img alt="Screenshot of a log message containing a Vector and an Exception." src="$(root_url)/assets/img/log arguments inspector.png" width="1040" height="1106" style="max-width: 500px;">
60+
61+
62+
## Hiding logs for a cell
2563

2664
If a package logs warnings or info messages that you want to hide (especially in the static export of the notebook), then the option to hide logs can be toggled by clicking on the cell menu (the three dots on the right).
2765

28-
![image](https://user-images.githubusercontent.com/9824244/166149026-98e8d29d-4162-46ae-be1f-bb296059e2fd.png)
66+
<img alt="Screenshot of button to hide logs." src="$(root_url)/assets/img/log hiding.png" width="1040" height="352" style="max-width: 500px;">
2967

30-
### Logging progress
68+
To filter logs more specifically, you can use a package like [LoggingExtras.jl](https://github.com/JuliaLogging/LoggingExtras.jl).
69+
70+
71+
## Logging progress
3172

3273
Pluto supports an integration with the [ProgressLogging.jl](https://github.com/JuliaLogging/ProgressLogging.jl) package which can be used to display a progress bar in the log message area:
3374

3475
<img alt="Screen recording of a Progress log going from 0% to 100%." src="$(root_url)/assets/img/progress log demo.gif" width="826" height="572" style="max-width: 400px;">
3576

3677
## Writing to standard output
78+
You can also use Julia functions like `println`, `display`, `@show` or `show`, which will write information to the **standard output stream**. This is the "old" way of logging information, but it is still supported in Pluto in case you need it.
79+
80+
81+
<img alt="Screenshot of standard-out logging." src="$(root_url)/assets/img/log stdout.png" width="1040" height="352" style="max-width: 500px;">
82+
83+
84+
### Use Logging instead of stdout!
85+
We recommend using Logging instead of `println`. There are many advantages of using Logging instead of writing to standard output:
86+
- Logging works when writing multi-threaded code. `println` will mix different threads' output together, making it unreadable.
87+
- Logging allows for more structured information (from the 2nd argument onwards). For example, you can log a `Dict` and inspect it in Pluto. You can even log `plot(data)` and see the plot!
88+
- Logging can be easily filtered/disabled by the caller of a function. This is useful when writing packages. It can improve the experience and performance of your package.
89+
90+
### Disable capturing of standard output
91+
By default, Pluto captures the standard output stream and shows it in the notebook. To disable this, and show it inside the terminal instead, the `capture_stdout=false` option can be provided to `Pluto.run` when launching Pluto. Learn more about [configuring Pluto](../configuration/).
92+
3793

38-
To disable capturing and showing standard output inside Pluto and show it inside the terminal instead the `capture_stdout=false` option can be provided to `Pluto.run` when launching Pluto.

0 commit comments

Comments
 (0)