Search code examples
rustrust-cargo

How to use environment variables for debugging in rust?


I am creating a plugin for swc. It fails and I was told to add an environment variable for debugging. RUST_LOG=trace and SWC_DEBUG=1 Where should I put these variables? To what file? If I write them before "cargo test" - an error, an unrecognized command. help me please


Solution

  • If you are running your code on Unix, you need to add them in terminal right before execution command.

    E.g.: RUST_LOG=trace SWC_DEBUG=1 cargo test or RUST_LOG=trace SWC_DEBUG=1 ./my_program_name.

    If you running your code from Powershell on Windows, it is not so easy and requires 2 commands:

    > $env:RUST_LOG="trace"
    > $env:SWC_DEBUG=1
    > cargo test
    

    You may read more about them on Wikipedia.