Logging Is Powerful
Learn about why logging is powerful in our Rails application.
We'll cover the following
Crafting informative log messages for efficient troubleshooting and identification
Earlier, we set up lograge to change the format of our logs. The reason is that almost every tool for examining logs assumes one message per line, and that’s not how Rails logs by default. This matters because even the most underfunded production operations system tends to include a way to look at application logs. It might require using ssh
to connect to the production server and then using tail
, grep
, sed
, and awk
to filter the log
file, but usually there is a way to look at the logs.
Often, when there is a problem in production that no one can explain, the solution is to add more logging, deploy the app, and wait for the problem to happen again so we can get more data. This might be rudimentary, but it’s still powerful!
Logging is an extremely simple way to provide information about what the app is doing and why, and it’s a concept that almost any developer of any level of experience can understand and use effectively.
That said, not all log messages are equally effective, so we want to make sure that we and our team are writing good log messages. Consider this code:
Get hands-on with 1200+ tech skills courses.