How to use Ruby Logger in Rails ?

The Logger class, as the name suggests provides Logging functionality to jot down important points that you can use to output different kind of messages.
The messages can be of different severities aka levels;

LEVEL SUMMARY
UNKNOWN Unknown messages are the unexpected or random messages and they should always be logged.
FATAL An error that was not handled and could lead to program crashing
ERROR An error that can be handled
WARN A warning
INFO Generic information about the usage from the code being executed
DEBUG Information that was deduced during debugging

The order goes like;
debug < info < warn < error < fatal < unknown

They work as;
In production mode, you can set-up your Logger to output the messages which are either INFO messages or of the WARN level.
While in development mode, you would want to keep a tab on the program’s state and its status and therefore, you can set the Logger to the DEBUG level.

The interface is normally used as follows;

ruby logger 3

You also have the option to set an expiration date to the Log file. For ex, I want to keep the logs only for the current month. In that case I will be proceeding as follows:

ruby logger

And on an application level,

Ruby logger 2

Happy logging !

Signing out,

Niyanta Zamindar
Ruby on Rails Developer 

Subscribe For Latest Updates

Related Posts

Leave a Comment

Your email address will not be published. Required fields are marked *

en_USEnglish