Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using logger in Rails 4

I'm working on a Rails 4 project, and I can't seem to make anything show up in my development log when I call Rails.logger.debug "test" I've tried searching online but I feel like I haven't made much progress. How would I go about setting up a logger and telling it to write in my development log file?

Any help would be greatly appreciated.

like image 357
Michael Liu Avatar asked Jul 19 '13 15:07

Michael Liu


People also ask

What is logger in Rails?

Rails makes use of the ActiveSupport::Logger class to write log information. Other loggers, such as Log4r , may also be substituted. You can specify an alternative logger in config/application.rb or any other environment file, for example: config. logger = Logger.

How do I create a log file in rails?

If you want to change all the default logging for that specific model, you can simply use User. logger = Logger. new(STDOUT) or wherever you want to log to. In the same way, ActiveRecord::Base.

Where does Rails logger write to?

In a Rails app, logs are stored under the /log folder. In development mode, the development. log file is used & you see log output on the terminal you're running rails server on.


1 Answers

I think you should use it like this in your method. Checkout section 2.3 here

def your_method     logger.debug "This is from debug"   logger.info "This is from info" end 
like image 95
AnkitG Avatar answered Sep 22 '22 22:09

AnkitG