log errors and use correct env variable