Hi there,
I am very confused by the interaction(s?) between Logging.jl
, JuliaFormatter.jl
and Documenter.jl
. My initial problem was that I had blocks like this in my package documentation:
```@example
my_function() # returns 5
```
Rendering in the HTML docs as:
my_function() # returns 5
┌ Warning: My warning message.
└ @ MyModule ~/path/to/my/source/file.jl:42
5
I have been willing to remove the warning from the generated docs, because I know it will be fixed in the future and it’s just confusing at this point in the docs. The following does work:
```@example
using Logging # hide
with_logger(NullLogger()) do # hide
my_function()
end # hide
```
Which correctly renders as:
my_function()
5
But then JuliaFormatter.jl
reformats the example to add the required indentation, which leaves me with the following rather unsatisfying situation:
```@example
using Logging # hide
with_logger(NullLogger()) do # hide
my_function()
end # hide
```
Rendering as:
my_function()
5
I have tried adding the following lines to leave instructions to JuliaFormatter.jl
in a way that would not be rendered in the final docs:
#! format: off
#! format: off # hide
# hide #! format: off
None of which worked. So here is my first question then: How can I use #! format: off
in my docstrings @example
blocks?
I went for another approach then:
```
using Logging # hide
logger_safe = global_logger(NullLogger()) # hide
my_function()
global_logger(logger_safe) # hide
```
But this did not work and rendered as:
my_function()
┌ Warning: My warning message.
└ @ MyModule ~/path/to/my/source/file.jl:42
5
How come with_logger()
appears to work in docstrings @example
blocks and yet global_logger()
does not?
Since my docs are rather long to generate, I have then decided to toy around with a smaller project just to better understand what is happening here, using the following structure:
JuliaTests/
├── Manifest.toml
├── Project.toml
└── src/
├── JuliaTests.jl
└── main.md
src/JuliaTests.jl
module JuliaTests
function f()
@info "INFO message"
@warn "WARN message"
@error "ERROR message"
5
end
export f
end # module JuliaTests
src/main.md
```@example JuliaTests
using JuliaTests
f()
```
```@example JuliaTests
function g()
@info "INFO message"
@warn "WARN message"
@error "ERROR message"
8
end
g()
```
Then I ran:
$ julia --project=.
julia> using JuliaTests
julia> using Documenter
julia> makedocs(;modules=[JuliaTests], sitename="toy")
Only to figure out that the resulting file in build/main/index.html
was now rendered as:
using JuliaTests
f()
5
function g()
@info "INFO message"
@warn "WARN message"
@error "ERROR message"
8
end
g()
8
Which confuses me even more, because the logged messages are now not rendered within the resulting docs. My initial problem was to remove the unwanted ones in my actual package.
Why would there be a difference between my package rendering and my MWE? What is Documenter.jl
policy regarding Logged messages? How can we control whether they should be rendered or not as part of the resulting, generated html doc?