Is there any way to display Rails' log files in the browser?

This might be (read: probably is) a dumb question, but here goes...

Is there a simple, preferably non third-party, way to display Rails logs in the browser? It gets kind of old opening a log file, then closing it and re-opening it on the next error. It would be superfantastic to just to go domain.tld/logs, which would require user authentication, of course.

Answers


All you need is to open log file and put its content into browser.

Realted topic: ruby: all ways to read from file.

Also you should know that your logs grow very fast, and it's not a good idea to show whole log in browser. You can just open last 100-200 rows. Related topic: Reading the last n lines of a file in Ruby?

Also you can try this solution: http://newrelic.com/. It is more complex and little oftopic, but quite useful.


For reference, there is a very simple way to do this. However, you would want to protect this page with some sort of authentication/authorization.

Controller:

lines = params[:lines]
if Rails.env == "production"
  @logs = `tail -n #{lines} log/production.log`
else
  @logs = `tail -n #{lines} log/development.log`
end

Log File View:

<pre><%= @logs %></pre>

View to display link:

<%= link_to "log file", log_path(lines: 100) %>

Routes:

get 'logs/:lines' => "pages#log", as: "log"

I created a for this purpose called browserlog.

Installing is just a matter of adding the gem to the Gemfile:

gem 'browserlog'

Afterwards all you need is to mount the engine on the route you want:

MyApp::Application.routes.draw do
  mount Browserlog::Engine => '/logs'
end

Once that's set up, accessing /logs/development (or production, test, etc) will show a window like this:

browserlog_screenshot http://andredieb.com/assets/images/browserlog1.png


Need Your Help

Choose Music from iPhone app? - iPhone SDK

objective-c iphone cocoa-touch xcode

Can anyone give me a head starters on this question. How would I be able to make an app that searches through your music contents that are already synced on your phone and play them. I don't want ...

Clicking all elements of a specific class in JavaScript?

javascript html web console

I'm new to JavaScript. I'm trying to create a script that will click all elements that belong to a specific class. My code doesn't seem to be working; I've run it through several different debugging