The .env file contains pairs of names and values of environment variables. For our service, we will set the RUST_LOG, RUST_BACKTRACE, and ADDRESS variables:
RUST_LOG=debug
RUST_BACKTRACE=1
ADDRESS=0.0.0.0:1234
As you can see, we set all the targets of the logger to the debug level, because cargo doesn't use dotenv and therefore skips these settings.
The RUST_BACKTRACE variable sets the flag to print a backtrace of the application in the case of panic.
Store this file in the working directory from which you will run the application. You can have multiple files and use them for different configurations. This file format is also compatible with Docker and can be used to set variables to the container.
I recommend that you add the .env file to your .gitignore to prevent leaking of sensitive or local data. This means that every user or developer who works with your project has their own environment and needs their own version of the .env file.