Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Rails 3.0's default log path?

I have to change my rail application's default log path because of my company's internal software deployment process: basically my rails app ends up on a read-only location, and I need the log files written in a directory "made for this".

With Rails 2.x we used to add some black magic in our FCGI script to force that in when deployed on prod. hosts:

class Rails::Configuration
   def default_log_path
     File.join(ENV['SOME_ENVIRONMENT_VAR'], "var/output/logs/rails.log")
   end
 end

However, Configuration isn't a class anymore in Rails 2.3 (it's a module), and it appears to me there isn't any default_log_path involved there anymore as well...

like image 205
Romain Avatar asked Oct 15 '10 14:10

Romain


People also ask

Where are rails logs stored?

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.

How do I create a log file in Ruby on rails?

Since the logger library comes with Ruby, there's no need to install any gems or other libraries. To begin using the logger library, simply require 'logger' and create a new Logger object. Any messages written to the Logger object will be written to the log file.

What is rails logger debugging?

logger. debug , or in short logger. debug writes the parameter text to a log file. This log file is by default environment specific. If you are currently running rails in development environment then the log file in use is log/development.

What are rails logs?

Rails uses six different log levels: debug, info, warn, error, fatal, and unknown. Each level defines how much information your application will log: Debug: diagnostic information for developers and system administrators, including database calls or inspecting object attributes. This is the most verbose log level.


2 Answers

The config.log_path setting has been deprecated - the recommended solution is now:

config.paths.log = "/some/path/#{Rails.env}.log"

like image 175
Cameron Yule Avatar answered Oct 04 '22 18:10

Cameron Yule


As of Rails 3.2.3, looks like the log pathname is also defined in Rails::Rack::LogTailer#initialize, and that comes from Rails::Server#log_path.

LOG_PATH = "log/mylog.log"

require 'rails/commands/server'
module Rails
  class Server
    def log_path
      LOG_PATH
    end
  end
end

class Application < Rails::Application
  ...
  config.paths['log'] = LOG_PATH
  ...
end
like image 20
aceofspades Avatar answered Oct 04 '22 18:10

aceofspades