Skip to content

Commit f7f58f0

Browse files
authored
Move debug logs in .tailwindcss folder (#20416)
Instead of writing debug logs (triggered by using `DEBUG=*`) in the root of the project as `tailwindcss-<pid>.log`, we will write them to `.tailwindcss/logs/scanner-<timestamp>-<pid>.log` instead. The reasoning for this is that we won't pollute the root of the project. Another reason is that if you don't ignore `.log` files via `.gitignore`, it could be that you end up in a loop if you use `DEBUG=* vite` because a new `.log` file might trigger a new build. We noticed this while looking at #20382. The `.tailwindcss` folder will come with a `.gitignore` file that ignores everything (`*`). ## Test plan 1. Nothing really changed here, all tests should pass Testing this in a local project, it looks like this: <img width="483" height="165" alt="file-35bfc43606c556f2380a161c7595d103" src="https://github.com/user-attachments/assets/629519c8-8f2b-46ee-8046-9ba3749f319a" />
1 parent de9e71c commit f7f58f0

1 file changed

Lines changed: 39 additions & 7 deletions

File tree

crates/oxide/src/scanner/init_tracing.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,52 @@ pub fn init_tracing() {
3737
return;
3838
}
3939

40-
let file_path = format!("tailwindcss-{}.log", std::process::id());
41-
let file = OpenOptions::new()
40+
let root = Path::new(".tailwindcss");
41+
let logs_dir = root.join("logs");
42+
if let Err(err) = std::fs::create_dir_all(&logs_dir) {
43+
eprintln!(
44+
"{} Failed to create {}, skipping debug logs ({err})",
45+
dim("[DEBUG]"),
46+
highlight(&logs_dir.display().to_string())
47+
);
48+
return;
49+
}
50+
51+
// Ensure everything inside `.tailwindcss/` is ignored by git. The file is only created if it
52+
// doesn't exist yet, an existing `.gitignore` is left untouched.
53+
if let Ok(mut file) = std::fs::File::create_new(root.join(".gitignore")) {
54+
_ = file.write_all(b"*\n");
55+
}
56+
57+
let file_path = logs_dir.join(format!(
58+
"scanner-{}-{}.log",
59+
std::time::SystemTime::now()
60+
.duration_since(std::time::UNIX_EPOCH)
61+
.map(|d| d.as_millis())
62+
.unwrap_or(0),
63+
std::process::id()
64+
));
65+
let file = match OpenOptions::new()
4266
.create(true)
4367
.append(true)
4468
.open(&file_path)
45-
.unwrap_or_else(|_| panic!("Failed to open {file_path}"));
69+
{
70+
Ok(file) => file,
71+
Err(err) => {
72+
eprintln!(
73+
"{} Failed to create {}, skipping debug logs ({err})",
74+
dim("[DEBUG]"),
75+
highlight(&file_path.display().to_string())
76+
);
77+
return;
78+
}
79+
};
4680

47-
let file_path = Path::new(&file_path);
48-
let absolute_file_path = dunce::canonicalize(file_path)
49-
.unwrap_or_else(|_| panic!("Failed to canonicalize {file_path:?}"));
81+
let absolute_file_path = dunce::canonicalize(&file_path).unwrap_or_else(|_| file_path.clone());
5082
eprintln!(
5183
"{} Writing debug info to: {}\n",
5284
dim("[DEBUG]"),
53-
highlight(absolute_file_path.as_path().to_str().unwrap())
85+
highlight(&absolute_file_path.display().to_string())
5486
);
5587

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

0 commit comments

Comments
 (0)