aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/main.rs')
-rw-r--r--crates/shirabe/src/main.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/crates/shirabe/src/main.rs b/crates/shirabe/src/main.rs
index 6eb8e4cb..49ee61f3 100644
--- a/crates/shirabe/src/main.rs
+++ b/crates/shirabe/src/main.rs
@@ -1,6 +1,32 @@
//! ref: composer/bin/composer
use shirabe_php_shim::{PHP_ENV, PHP_SERVER};
+use std::io::IsTerminal as _;
+
+/// Initialize a tracing subscriber from the environment variable `$SHIRABE_TRACING`.
+fn init_tracing() {
+ let Ok(directives) = std::env::var("SHIRABE_TRACING") else {
+ return;
+ };
+ if directives.is_empty() {
+ return;
+ }
+
+ let env_filter = match tracing_subscriber::EnvFilter::builder().parse(&directives) {
+ Ok(env_filter) => env_filter,
+ Err(e) => {
+ eprintln!("SHIRABE_TRACING: invalid filter directives {directives:?}: {e}");
+ return;
+ }
+ };
+
+ tracing_subscriber::fmt()
+ .with_env_filter(env_filter)
+ .with_writer(std::io::stderr)
+ .with_ansi(std::io::stderr().is_terminal())
+ .with_span_events(tracing_subscriber::fmt::format::FmtSpan::CLOSE)
+ .init();
+}
fn main() {
// TODO(phase-c): PHP: `$xdebug = new XdebugHandler('Composer'); $xdebug->check(); unset($xdebug);`
@@ -28,6 +54,8 @@ fn main() {
.expect("failed to build the top-level tokio runtime");
let _runtime_guard = runtime.enter();
+ init_tracing();
+
let result = shirabe::run(std::env::args().collect());
let exit_code = match result {
Ok(exit_code) => exit_code,