Skip to content

Conversation

@kleinesfilmroellchen
Copy link

@kleinesfilmroellchen kleinesfilmroellchen commented Dec 11, 2025

As per discussion in #3038 (comment), we want to move to using log for all of our logging needs. This PR does both the backend work, and also adds an env_logger configured with:

  • default level zola=info, so that only Zola’s output is visible by default (and no debugging)
  • respecting terminal color configuration (CLICOLOR/NO_COLOR/terminal detection etc.)
  • simple output format <Level> <Message> matching mdBook, except for INFO which only prints the message

Also migrate to anstyle which is more flexible than termcolor and also provides a utility for color mode auto-detection.

Caveats:

  • Some commands have slightly changed output (e.g.
    removed “warning” text for log::warn), but a lot
    of them might still contain formatting symbols
    like “->” and “>”.
  • Init command (and its tooling) is unchanged, as
    it should be a nice interactive command.
  • There is no log::success, so the success-info
    distinction has been lost in some places.
  • Separate prints close to each other have been
    transformed into one log call each. They might
    look less related than they did before.
  • No new logging is added. Many components might
    benefit from extra logging within them.

Sanity check:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

(Delete or ignore this section for documentation changes)

  • Are you doing the PR on the next branch?

If the change is a new feature or adding to/changing an existing one:

  • Have you created/updated the relevant documentation page(s)?

Copy link
Collaborator

@Keats Keats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit too much. A lot of it that we always want to show should stay as println. I think logs is going to be used mostly for perf/what's happening at the info level and warnings like in your PR. I don't have a clear view of what it would look like yet but I'm fairly sure everything we're printing during a normal run (such as link checking, timing etc) should stay println

});

println!(
log::info!(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think all that functions should stay println? it's stuff we always want the end user to see, logs should be reserved to things like debugging or warnings

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as the logging framework is configured correctly, it’s very easy to always show these messages. Possibly using a special target for log.

let local_addr = listener.local_addr().unwrap();

println!(
log::info!(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anything in src should stay println/eprintln

@kleinesfilmroellchen
Copy link
Author

kleinesfilmroellchen commented Dec 12, 2025

I take issue with the current printing approach because it is sometimes hard to guess which subsystem is doing what unless the messages are very clear, and whether certain messages are even related. mdbook, which has a very similar CLI to zola, also uses log for printing its regular CLI output, using only a very basic style that includes the warning level and the message. (Technically, they use tracing, which is basically just a more advanced log. See e.g. here.)

@Keats
Copy link
Collaborator

Keats commented Dec 13, 2025

it is sometimes hard to guess which subsystem is doing what unless the messages are very clear

I don't want the classic [2017-11-09T02:12:24Z DEBUG main] for the main output of zola. We can define a basic formatter with env_logger (let's say just the message and changing colour for the level warning/error). We do lose the possibility of putting different colour inside a message but i guess that's fine. Can you add the formatting you had in mind in this PR as well?

@kleinesfilmroellchen
Copy link
Author

it is sometimes hard to guess which subsystem is doing what unless the messages are very clear

I don't want the classic [2017-11-09T02:12:24Z DEBUG main] for the main output of zola.

Me neither!

We can define a basic formatter with env_logger (let's say just the message and changing colour for the level warning/error). We do lose the possibility of putting different colour inside a message but i guess that's fine.

I’m fairly certain you can still inject ANSI codes into the log message, AFAIK there’s quite a bit of support around that (color macros, detecting terminal color support, etc.). I’m not sure where we do that right now though, didn’t see it when going through the print statements. If I missed something please point it out and I’ll definitely add it back.

Can you add the formatting you had in mind in this PR as well?

Okay, so I will add an env_logger with default config (so RUST_LOG works as above) and mdbook-like formatting, no coloring of the message, and colored log level. I won’t add an env_logger to the testing infra or any other binaries that may be floating around, just the main CLI.

Cargo.toml Outdated
# For essence_str() function, see https://github.com/getzola/zola/issues/1845
mime = "0.3.16"
env_logger = "0.11"
anstyle = "1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are already using termcolor in components/console
It's fine to replace it but let's not have both

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can remove the anstyle dependency, at least when disabling the color feature of env_logger. (That might require us to detect terminals manually tho, I will see.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking into this more, we should use anstyle instead of termcolor. It also has a utility crate (anstream) which provides auto-color-detection, pretty much matching the manual logic in console but more accurate (and compatible with old Windows terminals). So I now also ported console to anstyle which was simple enough.

@Keats
Copy link
Collaborator

Keats commented Dec 14, 2025

I'll have a look at the output tomorrow

@Keats
Copy link
Collaborator

Keats commented Dec 15, 2025

Looking at the output:

  1. we should default to showing at least warn when env var not set
  2. no need for INFO label. Ideally no need for WARN label as well but coloring the text is a bit trickier...

@kleinesfilmroellchen
Copy link
Author

Looking at the output:

1. we should default to showing at least warn when env var not set

I noticed this too earlier when testing, so now we fall back to zola=info as a logging configuration. This prevents other crates from adding their own confusing INFO prints by default (though I have not observed this so far).

2. no need for INFO label. Ideally no need for WARN label as well but coloring the text is a bit trickier...

I personally disagree, but will do

@kleinesfilmroellchen kleinesfilmroellchen force-pushed the logging branch 2 times, most recently from d781f82 to 433e75f Compare December 15, 2025 11:47
This change ports all println and console::* users
to use log::* with the appropriate level. Caveats:
- Some commands have slightly changed output (e.g.
  removed “warning” text for log::warn), but a lot
  of them might still contain formatting symbols
  like “->” and “>”.
- Init command (and its tooling) is unchanged, as
  it should be a nice interactive command.
- There is no `log::success`, so the success-info
  distinction has been lost in some places.
- Separate prints close to each other have been
  transformed into one log call each. They might
  look less related than they did before.
- No new logging is added. Many components might
  benefit from extra logging within them.
As per discussion, this only prints the log level
with basic coloring as well as the message.

Additionally, replace termcolor by
anstyle+anstream which provides accurate terminal
detection and more formatting capabilities.
(anstyle is already a dependency, and termcolor is
mainly present in some older package versions.)
@Keats
Copy link
Collaborator

Keats commented Dec 23, 2025

Sorry can you rebase? The giallo branch merge created a bunch of conflicts

@EvanCarroll
Copy link

This doesn't make sense, if you're using Axum and Tokio why aren't you tracing for logging?

@Keats
Copy link
Collaborator

Keats commented Dec 24, 2025

We wouldn't use anything from tracing other than the logs so it wouldn't make sense to use it

@EvanCarroll
Copy link

Tracing would allow you to run debugging information on a span covering thinks like shortcode expansion or calls to cmark, and get comprehensive reporting -- when desired -- about what took time in generating the site. It would also allow you to get comprehensive timings for requests and it easily flows with axum/tokio (it's the support mechanism of doing this). Not to mention, I think it's probably already in the req stack somewhere by way of hyper-util and axum. So it's basically more power and free.

If you want a patch to show it off and see, accept my axum patch and I'll provide an alternative for you to A-B.

@Keats
Copy link
Collaborator

Keats commented Dec 24, 2025 via email

@EvanCarroll
Copy link

EvanCarroll commented Dec 24, 2025

I'm not trying to be standoffish and it's not just about the dev server either (though I don't know why you wouldn't want the things you don't care about).

  • It's no more difficult to use the free macros in tracing and.
  • The framework is already in use by our deps.
  • It will allow you to benchmark across async tasks and provide debugging about compilation speed.

It's literally switching log::info! to tracing::info!. There is even a note about migration to tracing from log just to ease the difficulty since everyone is moving that direction https://docs.rs/tracing/latest/tracing/#for-log-users

@Keats
Copy link
Collaborator

Keats commented Dec 26, 2025

I'll well aware of tracing, but since we won't use any of it right now, there's no point adding it. As you said, it's easy to swap later if we want to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants