Skip to content

Write to log file when using DEBUG=* #17906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 7, 2025
Merged
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Upgrade: Automatically convert candidates with arbitrary values to their utilities ([#17831](https://github.com/tailwindlabs/tailwindcss/pull/17831), [#17854](https://github.com/tailwindlabs/tailwindcss/pull/17854))
- Write to log file when using `DEBUG=*` ([#17906](https://github.com/tailwindlabs/tailwindcss/pull/17906))

### Fixed

- Ensure negative arbitrary `scale` values generate negative values ([#17831](https://github.com/tailwindlabs/tailwindcss/pull/17831))
- Fix HAML extraction with embedded Ruby ([#17846](https://github.com/tailwindlabs/tailwindcss/pull/17846))
- Don't scan files for utilities when using `@reference` ([#17836](https://github.com/tailwindlabs/tailwindcss/pull/17836))
- Fix incorrectly replacing `_` with ` ` in arbitrary modifier shorthand `bg-red-500/(--my_opacity)` ([#17889](https://github.com/tailwindlabs/tailwindcss/pull/17889))
- Upgrade: Bump dependendencies in parallel and make the upgrade faster ([#17898](https://github.com/tailwindlabs/tailwindcss/pull/17898))
- Upgrade: Bump dependencies in parallel and make the upgrade faster ([#17898](https://github.com/tailwindlabs/tailwindcss/pull/17898))
Copy link
Contributor

Choose a reason for hiding this comment

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

🫣

Copy link
Member Author

Choose a reason for hiding this comment

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

🤫

- Don't scan `.log` files for classes by default ([#17906](https://github.com/tailwindlabs/tailwindcss/pull/17906))

## [4.1.5] - 2025-04-30

Expand Down
1 change: 1 addition & 0 deletions crates/oxide/src/scanner/fixtures/ignored-extensions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ lock
sass
scss
styl
log
63 changes: 61 additions & 2 deletions crates/oxide/src/scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ use fxhash::{FxHashMap, FxHashSet};
use ignore::{gitignore::GitignoreBuilder, WalkBuilder};
use rayon::prelude::*;
use std::collections::{BTreeMap, BTreeSet};
use std::fs::OpenOptions;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::sync::{self, Arc, Mutex};
use std::time::SystemTime;
use tracing::event;
use tracing_subscriber::fmt::writer::BoxMakeWriter;

// @source "some/folder"; // This is auto source detection
// @source "some/folder/**/*"; // This is auto source detection
Expand All @@ -35,18 +38,67 @@ static SHOULD_TRACE: sync::LazyLock<bool> = sync::LazyLock::new(
|| matches!(std::env::var("DEBUG"), Ok(value) if value.eq("*") || (value.contains("tailwindcss:oxide") && !value.contains("-tailwindcss:oxide"))),
);

fn dim(input: &str) -> String {
format!("\u{001b}[2m{input}\u{001b}[22m")
}

fn blue(input: &str) -> String {
format!("\u{001b}[34m{input}\u{001b}[39m")
}

fn highlight(input: &str) -> String {
format!("{}{}{}", dim(&blue("`")), blue(input), dim(&blue("`")))
}

fn init_tracing() {
if !*SHOULD_TRACE {
return;
}

let file_path = format!("tailwindcss-{}.log", std::process::id());
let file = OpenOptions::new()
.create(true)
.append(true)
.open(&file_path)
.unwrap_or_else(|_| panic!("Failed to open {file_path}"));

let file_path = Path::new(&file_path);
let absolute_file_path = dunce::canonicalize(file_path)
.unwrap_or_else(|_| panic!("Failed to canonicalize {file_path:?}"));
eprintln!(
"{} Writing debug info to: {}\n",
dim("[DEBUG]"),
highlight(absolute_file_path.as_path().to_str().unwrap())
);

let file = Arc::new(Mutex::new(file));

let writer: BoxMakeWriter = BoxMakeWriter::new({
let file = file.clone();
move || Box::new(MutexWriter(file.clone())) as Box<dyn Write + Send>
});

_ = tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE)
.with_writer(writer)
.with_ansi(false)
.compact()
.try_init();
}

struct MutexWriter(Arc<Mutex<std::fs::File>>);

impl Write for MutexWriter {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.lock().unwrap().write(buf)
}

fn flush(&mut self) -> io::Result<()> {
self.0.lock().unwrap().flush()
}
}

#[derive(Debug, Clone)]
pub enum ChangedContent {
File(PathBuf, String),
Expand Down Expand Up @@ -394,7 +446,10 @@ impl Scanner {
fn read_changed_content(c: ChangedContent) -> Option<Vec<u8>> {
let (content, extension) = match c {
ChangedContent::File(file, extension) => match std::fs::read(&file) {
Ok(content) => (content, extension),
Ok(content) => {
event!(tracing::Level::INFO, "Reading {:?}", file);
(content, extension)
}
Err(e) => {
event!(tracing::Level::ERROR, "Failed to read file: {:?}", e);
return None;
Expand Down Expand Up @@ -706,7 +761,11 @@ fn create_walker(sources: Sources) -> Option<WalkBuilder> {

match (current_time, previous_time) {
(Some(current), Some(prev)) if prev == current => false,
_ => true,
_ => {
event!(tracing::Level::INFO, "Discovering {:?}", path);

true
}
}
}
});
Expand Down
9 changes: 3 additions & 6 deletions packages/@tailwindcss-cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ async function handleError<T>(fn: () => T): Promise<T> {
}

export async function handle(args: Result<ReturnType<typeof options>>) {
eprintln(header())
eprintln()

using I = new Instrumentation()
DEBUG && I.start('[@tailwindcss/cli] (initial build)')

Expand All @@ -87,8 +90,6 @@ export async function handle(args: Result<ReturnType<typeof options>>) {

// Ensure the provided `--input` exists.
if (!existsSync(args['--input'])) {
eprintln(header())
eprintln()
eprintln(`Specified input file ${highlight(relative(args['--input']))} does not exist.`)
process.exit(1)
}
Expand All @@ -97,8 +98,6 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
// Check if the input and output file paths are identical, otherwise return an
// error to the user.
if (args['--input'] === args['--output'] && args['--input'] !== '-') {
eprintln(header())
eprintln()
eprintln(
`Specified input file ${highlight(relative(args['--input']))} and output file ${highlight(relative(args['--output']))} are identical.`,
)
Expand Down Expand Up @@ -328,8 +327,6 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
await write(output, args, I)

let end = process.hrtime.bigint()
eprintln(header())
eprintln()
eprintln(`Done in ${formatDuration(end - start)}`)
}

Expand Down