Logging and stdout

To help with debugging your code, Pluto supports showing messages printed with the standard library Logging module. This can be done using the @info, @warn and @error macro.

For example, you can use @info somewhere in your code to see the value of a variable while your code runs:

begin
	result = 0
	
	for i in 1:5
		x = i^2
		@info("Current value", x)
		result += x
	end
	result
end
Screenshot of the log messages from the previous code example.

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.

Screenshot of the log messages with 'i' added.

Log levels: @debug, @info, @warn, @error

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.

Screenshot of different log levels displayed in different colors.

@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.

Special log arguments

Pluto will use its rich object inspector to display the arguments of log messages. This means that you can log complex objects like Dicts, DataFrames, or even plots, and they will be displayed in a nice way in the logs.

Here is an example of logging a Vector, and an Exception:

Screenshot of a log message containing a Vector and an Exception.

Hiding logs for a cell

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).

Screenshot of button to hide logs.

To filter logs more specifically, you can use a package like LoggingExtras.jl.

Logging progress

Pluto supports an integration with the ProgressLogging.jl package which can be used to display a progress bar in the log message area:

Screen recording of a Progress log going from 0% to 100%.

Writing to standard output

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.

Screenshot of standard-out logging.

Use Logging instead of stdout!

We recommend using Logging instead of println. There are many advantages of using Logging instead of writing to standard output:

  • Logging works when writing multi-threaded code. println will mix different threadsโ€™ output together, making it unreadable.
  • 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!
  • 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.

Disable capturing of standard output

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.