The best thing I learned this week isn't exactly a mind bender, but it saves some clicks, and is worth writing about. I learned that you can pipe in custom logger output options right into an execution script.
I've been working on an Elixir/Phoenix project, and since the release of the production environment we have had to take steps to ensure data insertions are executable across multiple databases. The basic components are a CSV containing the data, a file containing the insertion functions, and a script to execute the process, which looks like this:
The logger output wasn't much of a concern, until we started running these scripts on our staging database and we needed to be absolute sure the data was inserting as expected. The process of inserting data to staging was:
- Dry run the script locally
- Save the logger output to a file
- Dry run the script on staging
- Save that logger output to a file
- Diff the two files
While test running this the first time I realized that our local dev environment was printing out a much more detailed log than staging, which created an issue when attempting to diff the two files.
The local logging:
And the logging from staging:
The long way to manually sync the local logging output is go to the
config > dev.exs file, and modify this line:
To match the logging output of staging:
When finished running those scripts the changes would need to be reverted.
Its not a terrible workflow, but piping the logger configuration directly into the execution script is far more efficient:
With this simple addition to the script the logging detail levels match, and theres no need to temporary alter the config files.
This post is part of an ongoing This Week I Learned series. I welcome any critique, feedback, or suggestions in the comments.