Bit of context: I’m an Economics major that somehow ended up developing an API that’s becoming a whole software project, so please bear with me.

So, after I got asked to add logs I noticed I should have a development and a production environment so my logs don’t get dirtied by my tests. After reading a bit I added a .env and a .env.development file. A bit overkill because they look like this:

.env:

 ENVIRONMENT=production

.env.development:

 ENVIRONMENT=development

In the future there might be database connections, so I’d rather keep this structure if possible.

Now, I also installed python-dotenv to load my environment variables, my code looks a bit like this:

import logging
import os
from dotenv import load_dotenv
load_dotenv('.env.development')

if os.environ.get('ENVIRONMENT') == 'production':
    log_dir = 'logs/logs_completo.log'
    log_error_dir = 'logs/logs_error.log'
elif os.environ.get('ENVIRONMENT') == 'development':
    log_dir = 'logs/logs_completo_dev.log'
    log_error_dir = 'logs/logs_error_dev.log'

So, my only problem is that, as it looks right now, the correct loading of an environment depends on me remembering to manually change load_dotenv('.env.development') to load_dotenv('.env') and vice versa.

Also, I’m developing on Windows and the docker machine uses Linux. My question is, how can I automate my environment selection, so I don’t accidentally send the development environment to production or accidentally work on production environment while testing? Should I add a bash file or something like that? How does that work with testing on Windows?

Thanks a lot and sorry if I’m using some concepts incorrectly.

2