diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-25 14:06:44 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-25 15:34:24 +0900 |
| commit | d4608662f28b9a5135986b1702afe3199957eabe (patch) | |
| tree | c75a42f12fb04c722dec87c135869f9737b5d272 /crates/shirabe/src/main.rs | |
| parent | 42b5f9e321c918cef542c120ad21ba8a7339eb29 (diff) | |
| download | php-shirabe-d4608662f28b9a5135986b1702afe3199957eabe.tar.gz php-shirabe-d4608662f28b9a5135986b1702afe3199957eabe.tar.zst php-shirabe-d4608662f28b9a5135986b1702afe3199957eabe.zip | |
feat(tracing): init tracing subscriber from $SHIRABE_TRACING
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/main.rs')
| -rw-r--r-- | crates/shirabe/src/main.rs | 28 |
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, |
