Basic Logging
Every application log file should include, at a minimum, a few essential pieces of information. The most basic of logging requirements would include some form of category to filter on and a timestamp. Ruby makes this easy for us and gives us a whole lot more.
With just a few simple lines of code, you can implement fully featured standardized logging across your entire application.
Let's look at a basic example:
require 'logger' logger = Logger.new(STDOUT) logger.debug("User 23643 logged in")
Here, we can see the logger
class being "required" like any other gem, after which we instantiate the class, as the logger
variable, passing STDOUT
as the first parameter (more on this soon), and finally, we call logger.debug
with our message.
When we run this script, we will see the following output:
What we're seeing here is the standard log format. This contains:
...