Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 0.22.0 (unreleased)

- Add proper logging; log output can be controlled with `RUST_LOG` environment variable
- Remove `ZOLA_PERF_LOG` environment variable; set `RUST_LOG=site=debug,zola=info` instead

## 0.21.0 (2025-07-14)

- Allow `github_alerts` at config.toml level
Expand Down
38 changes: 32 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ open = "5"
mime_guess = "2.0"
# For essence_str() function, see https://github.com/getzola/zola/issues/1845
mime = "0.3.16"
env_logger = { version ="0.11", default-features = false }

site = { workspace = true }
errors = { workspace = true }
Expand All @@ -49,7 +50,10 @@ reqwest = { workspace = true }

# Direct workspace deps used by the binary
ahash = { workspace = true }
anstream = { workspace = true }
anstyle = { workspace = true }
globset = { workspace = true }
log = { workspace = true }
percent-encoding = { workspace = true }
relative-path = { workspace = true }
serde_json = { workspace = true }
Expand All @@ -76,7 +80,8 @@ version = "0.21.0"
# External dependencies
ahash = "0.8"
ammonia = "4"
atty = "0.2.11"
anstream = "0.6"
anstyle = "1"
avif-parse = "1.3.2"
base64 = "0.22"
chrono = { version = "0.4.27", default-features = false, features = ["std", "clock"] }
Expand Down Expand Up @@ -109,7 +114,6 @@ slug = "0.1"
svg_metadata = "0.6"
syntect = "5"
tera = { version = "1.17", features = ["preserve_order", "date-locale"] }
termcolor = "1.0.4"
time = "0.3"
toml = "0.9"
unic-langid = "0.9"
Expand Down
1 change: 1 addition & 0 deletions components/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include = ["src/**/*"]
[dependencies]
serde = { workspace = true }
globset = { workspace = true }
log = { workspace = true }
once_cell = { workspace = true }
syntect = { workspace = true }
toml = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions components/config/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ impl Config {
if base_language_options == languages::LanguageOptions::default() {
return Ok(());
}
println!(
"Warning: config.toml contains both default language specific information at base and under section `[languages.{}]`, \
log::warn!(
"config.toml contains both default language specific information at base and under section `[languages.{}]`, \
which may cause merge conflicts. Please use only one to specify language specific information",
self.default_language
);
Expand Down
4 changes: 2 additions & 2 deletions components/console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2024"

[dependencies]
atty = { workspace = true }
anstream = { workspace = true }
anstyle = { workspace = true }
once_cell = { workspace = true }
termcolor = { workspace = true }

errors = { workspace = true }
55 changes: 13 additions & 42 deletions components/console/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,27 @@
use std::env;
use std::io::Write;

use once_cell::sync::Lazy;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};

/// Termcolor color choice.
/// We do not rely on ColorChoice::Auto behavior
/// as the check is already performed by has_color.
static COLOR_CHOICE: Lazy<ColorChoice> =
Lazy::new(|| if has_color() { ColorChoice::Always } else { ColorChoice::Never });
use anstream::{
AutoStream,
stream::{AsLockedWrite, RawStream},
};
use anstyle::{AnsiColor, Color, Style};

pub fn info(message: &str) {
colorize(message, ColorSpec::new().set_bold(true), StandardStream::stdout(*COLOR_CHOICE));
}

pub fn warn(message: &str) {
colorize(
&format!("{}{}", "Warning: ", message),
ColorSpec::new().set_bold(true).set_fg(Some(Color::Yellow)),
StandardStream::stdout(*COLOR_CHOICE),
);
colorize(message, &Style::new().bold(), AutoStream::auto(std::io::stdout()));
}

pub fn success(message: &str) {
colorize(
message,
ColorSpec::new().set_bold(true).set_fg(Some(Color::Green)),
StandardStream::stdout(*COLOR_CHOICE),
);
}

pub fn error(message: &str) {
colorize(
&format!("{}{}", "Error: ", message),
ColorSpec::new().set_bold(true).set_fg(Some(Color::Red)),
StandardStream::stderr(*COLOR_CHOICE),
&Style::new().bold().fg_color(Some(Color::Ansi(AnsiColor::Green))),
AutoStream::auto(std::io::stdout()),
);
}

/// Print a colorized message to stdout
fn colorize(message: &str, color: &ColorSpec, mut stream: StandardStream) {
stream.set_color(color).unwrap();
write!(stream, "{}", message).unwrap();
stream.set_color(&ColorSpec::new()).unwrap();
writeln!(stream).unwrap();
}

/// Check whether to output colors
fn has_color() -> bool {
let use_colors = env::var("CLICOLOR").unwrap_or_else(|_| "1".to_string()) != "0"
&& env::var("NO_COLOR").is_err();
let force_colors = env::var("CLICOLOR_FORCE").unwrap_or_else(|_| "0".to_string()) != "0";

force_colors || use_colors && atty::is(atty::Stream::Stdout)
fn colorize<S>(message: &str, color: &Style, mut stream: AutoStream<S>)
where
S: RawStream + AsLockedWrite,
{
writeln!(stream, "{color}{}{color:#}", message).unwrap();
}
1 change: 1 addition & 0 deletions components/markdown/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include = ["src/**/*"]
pest = "2"
pest_derive = "2"
gh-emoji = { workspace = true }
log = { workspace = true }
once_cell = { workspace = true }
pulldown-cmark = { workspace = true }
pulldown-cmark-escape = { workspace = true }
Expand Down
4 changes: 3 additions & 1 deletion components/markdown/src/codeblock/fence.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::ops::RangeInclusive;

use log;

fn parse_range(s: &str) -> Option<RangeInclusive<usize>> {
match s.find('-') {
Some(dash) => {
Expand Down Expand Up @@ -119,7 +121,7 @@ impl<'a> Iterator for FenceIter<'a> {
"copy" => return Some(FenceToken::EnableCopy),
lang => {
if tok_split.next().is_some() {
eprintln!("Warning: Unknown annotation {}", lang);
log::warn!("Unknown annotation {}", lang);
continue;
}
return Some(FenceToken::Language(lang));
Expand Down
3 changes: 2 additions & 1 deletion components/markdown/src/codeblock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod highlight;
use std::ops::RangeInclusive;

use errors::{Result, bail};
use log;
use syntect::util::LinesWithEndings;

use crate::codeblock::highlight::SyntaxHighlighter;
Expand Down Expand Up @@ -105,7 +106,7 @@ impl<'config> CodeBlock<'config> {
if config.markdown.error_on_missing_highlight {
bail!(msg);
} else {
eprintln!("Warning: {}", msg);
log::warn!("{}", msg);
}
}
let highlighter = SyntaxHighlighter::new(config.markdown.highlight_code, syntax_and_theme);
Expand Down
3 changes: 2 additions & 1 deletion components/markdown/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt::Write;
use crate::markdown::cmark::CowStr;
use errors::bail;
use gh_emoji::Replacer as EmojiReplacer;
use log;
use once_cell::sync::Lazy;
use pulldown_cmark as cmark;
use pulldown_cmark_escape as cmark_escape;
Expand Down Expand Up @@ -181,7 +182,7 @@ fn fix_link(
match context.config.link_checker.internal_level {
config::LinkCheckerLevel::Error => bail!(msg),
config::LinkCheckerLevel::Warn => {
console::warn(&msg);
log::warn!("{msg}");
link.to_string()
}
}
Expand Down
1 change: 1 addition & 0 deletions components/site/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ serde = { workspace = true }
chrono = { workspace = true }
globset = { workspace = true }
grass = { workspace = true }
log = { workspace = true }
minify-html = { workspace = true }
once_cell = { workspace = true }
rayon = { workspace = true }
Expand Down
10 changes: 4 additions & 6 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::net::IpAddr;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, RwLock};

use log;
use once_cell::sync::Lazy;
use rayon::prelude::*;
use tera::{Context, Tera};
Expand Down Expand Up @@ -352,7 +353,7 @@ impl Site {
messages.join("\n")
);
match self.config.link_checker.internal_level {
config::LinkCheckerLevel::Warn => console::warn(&msg),
config::LinkCheckerLevel::Warn => log::warn!("{msg}"),
config::LinkCheckerLevel::Error => return Err(anyhow!(msg)),
}
}
Expand All @@ -372,7 +373,7 @@ impl Site {
messages.join("\n")
);
match self.config.link_checker.external_level {
config::LinkCheckerLevel::Warn => console::warn(&msg),
config::LinkCheckerLevel::Warn => log::warn!("{msg}"),
config::LinkCheckerLevel::Error => return Err(anyhow!(msg)),
}
}
Expand Down Expand Up @@ -1251,10 +1252,7 @@ impl Site {
}

fn log_time(start: Instant, message: &str) -> Instant {
let do_print = std::env::var("ZOLA_PERF_LOG").is_ok();
let now = Instant::now();
if do_print {
println!("{} took {}ms", message, now.duration_since(start).as_millis());
}
log::debug!("{} took {}ms", message, now.duration_since(start).as_millis());
now
}
Loading