When it comes to application development, few languages give programmers greater happiness than Ruby – a language designed for programmer happiness– and when it comes to bringing Ruby to the world of web applications, the most common answer is Rails.
For those who don’t know, Ruby and Rails have been working together for years to power many of the applications we use on a daily basis. From web applications to mobile, Ruby is everywhere – there are even libraries specifically for IoT and drone application building!
When it comes to application building, one of the key technologies Ruby developers can’t live without is logging. Logging is a key piece of the application development process and luckily, Ruby has features like the Logger class to follow specific bits of code, allowing us to push information to stdout. This allows for easy stack tracing and troubleshooting insights.
But what happens once we release our code to the wild? Can we still use Logger to grab the information we need in a simple and succinct way?
Unfortunately, the answer is not that simple. While Logger statements can be left in code and will be pushed out to your logs, there is a cost of keeping this in production. The first cost is on the speed of the application. This may not be overbearing, but it can cause slowness to creep into the application over time. The secondary cost is on the person parsing through all the logs in order to discover relevant information. This can be almost a full time job.
Luckily, there is a better way to get a glimpse of our logs without dealing with the cycle of heading to the server, attempting to view logs as root, parsing the Logger messages, and hoping for the best.
Using a Gem
If you have ELK stack familiarity, the easiest solution is to use the Logstash-Logger Gem. This gem was developed with Logger in mind, but instead of sending the information to a local log, it pushes it to a Logstash Instance. This can then be used to ship logs to Kibana so the information is presented in a more visual, user-friendly way.
Another great gem is the Logstash-Formatter. In addition to extending the Logger class, the Logstash-Formatter also seems to format for use with tools other than Logstash (e.g. Redis, Kafka). While it looks like a useful option, this gem has not been updated in over 3 years.
Gems can often be the first go-to solution for Ruby developers, but if they aren’t well maintained, it may be better to look for options outside the gem ecosystem.
Many Ruby developers have found Heroku to be the first answer to their application cloud hosting needs. This is usually true in the initial release stages, before an application hits a larger audience or sees massive traffic. Heroku makes logging easy, especially if you are using a service like Logz.io that is linked to the Heroku Elements marketplace.
Simple add-ons make life much easier to get the logs and insights into the application, helping us to move our applications to the next level.
Other Cloud Services
The Cloud is still the ultimate answer when it comes to application deployment in this day and age. Furthermore, many cloud providers make it easy to access logs and monitor your application.
Similar to Heroku, Amazon Web Services has many ways to access and use logs for better insights. Other Platforms, like Engine Yard have been working on better log access for Rails developers as part of their focus for a while.
Ruby developers need the best access to their logs in order to better serve their end users. With plenty of options, from gems right in the code to using the tools provided by hosts, it should be easier than ever to see how your application is functioning and discover ways to make it better.
Logz.io is an AI-powered log analysis platform based on the open source ELK Stack that can be used to monitor applications and cloud-based infrastructure. Start your free trial or request a free demo today!